Gday experts,
I've created a composite user control (JSEAAnalysisDisplay) to use as a means of adjusting the data in a series of records (so it contains dropdownlists, rich text boxes, checkboxes, etc). I then have a form which contains two buttons (btnAnalysisAdd and btnAnalysisDelete) and a panel (panelAnalysis).
The way the form is meant to work is that the user can click the 'Add' button as many times as they desire to create several of these JSEAAnalysisDisplay controls within the panel in the form, adjust them as appropriately and then save it all back to the database.
In the code below you can see the methods I have tied to the two buttons to first add a new blank instance of the control, and then the other button to remove those with a field flagged.
The problem I have is that when I'm appending these new custom controls to the control list of the panel, they all get positioned on top of each other - thus effectively making them impossible for the user to navigate correctly. The only solution I could think of was to reprocess their locations after they are added to the control list and also when any are removed (to reposition those left around the deleted instances to compensate).
Initially this appears to have resolved my problem, but now I have encountered another flaw in my design - when there are several instances of the JSEAAnalysisDisplay control within the panel, enough to force the panel's autoscroll to display, any repositioning is done relative to the scroll! So when I delete several of the controls using my button the first control in the collection is repositioned wherever the scroll is currently positioned. That means that the user can then scroll back to the start of the panel and see nothing but white space.
So my question is this;
How can I correctly position my new user controls when added to the panel control collection so that when added they cleanly display in a flat list down the form. And also, when they are removed the controls reposition relative to the panel, not the scroll bars.
methods as follow;
private void btnAnalysisAdd_Click(objec
t sender, EventArgs e)
{
panelAnalysis.Controls.Add
(new JSEAAnalysisDisplay());
RepositionAnalysis();
}
private void btnAnalysisDelete_Click(ob
ject sender, EventArgs e)
{
for (int iCon = 0; iCon < panelAnalysis.Controls.Cou
nt;iCon++ )
{
// Is this an analysis display segment?
if (typeof(JSEAAnalysisDispla
y) == panelAnalysis.Controls[iCo
n].GetType
())
{
JSEAAnalysisDisplay curCon = (JSEAAnalysisDisplay)panel
Analysis.C
ontrols[iC
on];
if (curCon.IsSelected)
{
panelAnalysis.Controls.Rem
oveAt(iCon
);
iCon--;
}
}
}
RepositionAnalysis();
}
private void RepositionAnalysis()
{
for (int iCon = 0; iCon < panelAnalysis.Controls.Cou
nt; iCon++)
{
if(iCon > 0)
{
panelAnalysis.Controls[iCo
n].Locatio
n = new Point(
0,
panelAnalysis.Controls[iCo
n - 1].Location.Y +
panelAnalysis.Controls[iCo
n - 1].Height);
}
else
{
panelAnalysis.Controls[iCo
n].Locatio
n = new Point(0, 0);
}
}
}
Any help is appreciated, many thanks in advance.
Start Free Trial