possible bug in gridview?

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
 
J

Jon Beets

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
 
W

WebBuilder451

..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
 
J

Jon Beets

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
 
W

WebBuilder451

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top