I've run into a number of times now where I find myself having to refer to a column by its name, which rubs me the wrong way; for example, the following snippet to run through and check whether or not all of the selected cells are in the same column:
allDataCells =
true
;
foreach
(GridViewCellInfo cell
in
commandGridView.SelectedCells)
{
if
(cell.ColumnInfo.Name !=
"columnData"
)
{
allDataCells =
false
;
break
;
}
}
It bugs me that I'm using the text name rather than the actual column variable. I know, in my example scenario, that the column variable is actually "gridViewTextBoxColumn8" (which could be a better name, I know).
Other than comparing on the name variables, which is a little better:
gridViewTextBoxColumn8.Name == cell.ColumnInfo.Name
...is there a "good" way to do this? When given a GridViewCellInfo item, what's the type-safe and typo-safe way to compare the column?
Thanks!
Dave