DataGridView, DataSource and RowCount related query
-
Couldn't think of a decent subject. sorry. If I add a DataGridView to a Form in constructor and create and set its datasource there itself. Now, I also check the rowcount in the constructor and it comes out as zero. Can someone explain the reason? Here[^] is the question that triggered mine.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
-
Couldn't think of a decent subject. sorry. If I add a DataGridView to a Form in constructor and create and set its datasource there itself. Now, I also check the rowcount in the constructor and it comes out as zero. Can someone explain the reason? Here[^] is the question that triggered mine.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
I believe this is because the
RowCount
property is related to the rows visually represented by theDataGridView
control. According to your steps, after the constructor has run you have aDataGridView
control and aDataSource
attached to it that is filled with data, but theDataGridView
control hasn't done it's visual rendering yet. If you check the property after theDataGridView
has been rendered and displayed at least one time, you should get the expected value. Try placing an event handler on theForm.Shown
event and then put a break point in the handler and check theRowCount
property.Hold on a second here... Don't you think you might be putting the horse ahead of the cart?
-
I believe this is because the
RowCount
property is related to the rows visually represented by theDataGridView
control. According to your steps, after the constructor has run you have aDataGridView
control and aDataSource
attached to it that is filled with data, but theDataGridView
control hasn't done it's visual rendering yet. If you check the property after theDataGridView
has been rendered and displayed at least one time, you should get the expected value. Try placing an event handler on theForm.Shown
event and then put a break point in the handler and check theRowCount
property.Hold on a second here... Don't you think you might be putting the horse ahead of the cart?