DataGridView Row properties not working in Form_Load?

G

gadgetophile

Running VS2005 Release Candidate, I'm having a bit of a headache with
DataGridView row-level properties.

If I try to make changes to row properties (e.g. myDGV.Rows[0].ReadOnly
= true, or myDGV.Rows[0].Frozen = true) in the Form_Load, after
databinding, the changes do not "stick". Stepping through the code, I
can see definitely that the properties are set, and I can query their
values to show this.

However, the desired behaviour does not happen (e.g. the row is not
readonly, nor frozen). If I make the change later in the form
lifecycle (e.g. on grid mouseover) it works fine. Is this a known bug?
 
G

gadgetophile

I've actually resolved my own problem, but still believe there is a bit
of a bug, or at least an inconsistency in the way this is handled.

It turns out that I was setting the row properties in the Load event of
a user control, not the form itself. The issue was resolved by:

private void myControl_Load(object sender, EventArgs e)
{
this.ParentForm.Load += new EventHandler(ParentForm_Load);
}

void ParentForm_Load(object sender, EventArgs e)
{
// set row properties here, e.g.
myDataGridView.Rows[0].Frozen = true;
}

Regardless, I believe it is a bug that the row properties get accepted
in Control_Load, and no errors are raised. I would have though an
"index out-of-bounds" error would be appropriate if the Rows collection
was not initialised. Column properties work perfectly in Control_Load.
 

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

Top