This procedure seems to find the column number of the DG...so far.
public int getDataGridColumnNumber(DataGridTableStyle dataGridStyle, string columnName)
{
int columnNumber = -1;
foreach(DataGridColumnStyle colStyle in dataGridStyle.GridColumnStyles)
{
columnNumber = columnNumber + 1;
if(colStyle.HeaderText.CompareTo(columnName) == 0)
return columnNumber;
}
columnNumber = -1;
return columnNumber;
}
"Steve B." wrote:
I solved the casting error by binding dGrid.DataSource = dataTable;
However, running the previous statement gets the column location in the dataset NOT the datagrid.
This is a show stopper because I move columns around and must bindContents()
Ideas. Why is this difficult?
"Steve B." wrote:
Thanks for your input. A runtime error states a "Specified cast [DataTable] is invalid"
object a = dGrid.DataSource; //returns DataView obj
I also know the table name as well as the column name
Steve
"Shakir Hussain" wrote:
Try this
string myText = "My Column Text";
int position= ((DataTable)this.dataGrid1.DataSource).Columns[myText].Ordinal
--
Shak
(Houston)
"Steve B." <St****@discussions.microsoft.com> wrote in message
news:71**********************************@microsof t.com...
> How do I find the column (index) number at runtime of a particular
DataGrid column if I know the column header string
>
> //somthing like the following
> int x = datagrid.column["ID"];
>
>