possible bug in gridview?

  • Thread starter Thread starter WebBuilder451
  • Start date Start date
W

WebBuilder451

I'm attempting to dynamicly populate a bound gridview.

The first step is to clear all columns except for column 0.
for (int i = gvPreview.Columns.Count-1; i > 0; i--)
gvPreview.Columns.RemoveAt(i);
Second step is to add the selected bound fields using a check id as the
boundfield name. The check boxes are loaded into a list of controls.
foreach (Control Ctrl in ControlList)
if (((CheckBox)Ctrl).Checked)
{
BoundField bFld = null;
bFld = new BoundField();
bFld.DataField = Ctrl.ID.ToString();
bFld.HeaderText = Ctrl.ID.ToString();
gvPreview.Columns.Add(bFld);
}

so far it works.
on load the grid a blanlk except for a single check box in a template, this
is column 0.

After the check boxes are selected and loaded into a list the code above is
executed.

on first try it works fine. Even if i add an extra control to force a column
removeAt to be called

on second try the control is removed from column 0, but not the column. It
is like the column is being cleared of all its controls.
Note: This ony happens if it is a template column.

Is this a bug and is there a work around?



--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
Kes,

It looks a lot like the bug reported here
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=264031

This appears to be the cause of the problem I am seeing. I correctly
display a detailsview with some declarative datacontrolfields removed in
read only mode usiing item templates. When the detailsview is changed to
edit mode all my controls inside edit templates have disappeared. The
detailsview works correctly in edit mode when the declarative
datacontrolfields are not removed.

I am about to try the work around suggested in the article.

regards

Jon
 
..Thank you
much appreciated please let me know if the workaround works for you. I will
attempt this sometime today.


--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
Kes,

No unfortunately :-( Maybe the bugs is subtly different for a detailsview!

However I was able to hide the fields rather than remove them which achieves
the same result in this particular case

I hope you have more luck!

regards

Jon Beets
 
Thank you i think i may opt for that myself. much appreciated and good luck.
I consider this a help and an answer.
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
Back
Top