Saturday, July 15, 2006

More on DataPropertyName

If a DataGridViewColumn has a null DataPropertyName the columns index will be set to 0. (if there is more than 1 column like this, then 0,1,2, etc.) - this of course messes up the indexes of your other columns too.

So if you are capturing the cellclick event and you find that e.ColumnIndex is not what you expect, it may be that you forgot to bind one of your columns (not necessarily the same one you're clicking) to a DataColumn. This is particularly likely if one of your columns if a DataGridViewButtoncolumn, or some other column that has no data behind it - so you may not have noticed it wasn't bound.

This is the same problem I was running into with the DataGridViewImageColumn - but with this problem I have no workaround becuase it seems that binding the column properly causes the image not to show up - I'll have to make a test app to confirm this.

No comments: