Think by yourself: if someone decided to give a property
Text
to a class representing a column, what would it possibly mean? A header text? No, it would not make any sense, because the adequate class representing a header represent cell class; it's just the kind of a cell. So, you get the idea of that
Text
property from nowhere, quite naturally, there is no such thing; so this is just your fantasy.
The property
SelectedIndex
of this class is also your fantasy, perhaps a bit less unreasonable than the
Text
property. Again, think a bit: what kind of selection could be represented by such property of a column? A column is not selected. Depending on options, you can make selectable a single cell, a set of cells, a whole row, a set of rows or columns. But the index of selected column would not make any sense, just because it could be a set of columns. Such property would be redundant, so there is no such thing.
So, my advice is quite simple: instead of trying out some non-existing properties or other member which you just fantasized out, read original MSDN documentation and simply follow it. At least, use VS Intellisense. If you did it, you would easily (very easily) find out how selection is made:
DataGridView.SelectedCells Property (System.Windows.Forms)[
^],
DataGridView.SelectedRows Property (System.Windows.Forms)[
^],
DataGridView.SelectedColumns Property (System.Windows.Forms)[
^];
options:
DataGridView.SelectionMode Property (System.Windows.Forms)[
^],
DataGridView.MultiSelect Property (System.Windows.Forms)[
^];
see also:
DataGridView Class (System.Windows.Forms)[
^].
With "text", things are a bit trickier: you have to use untyped approach applicable to all cells, using the property
Value
of the type
System.Object
but the
runtime type of this properties value can be different: sometime it's string, sometimes something else. You can query actual type of any cell using its property
ValueType
. Please see:
DataGridViewCell.Value Property (System.Windows.Forms)[
^],
DataGridViewCell.ValueType Property (System.Windows.Forms)[
^].
This is the idea: there are difference cell types derived from the type
System.Windows.Forms.DataGridViewCell
. You can implement your own type with your own value type; then you have to implement the two properties referenced above accordingly. Please see:
DataGridViewCell Class (System.Windows.Forms)[
^].
It's not really hard. You just need to read MSDN and use the UI classes and their member as intended.
—SA