Q: Determing in a column in a datagrid

  • Thread starter Thread starter Geoff Jones
  • Start date Start date
G

Geoff Jones

Hi

Can anybody tell me how to find the column index in a DataGrid knowing only
the text in the column heading? Any sample code would be most useful.

Thanks in advance

Geoff
 
Geoff,

With styles?

When not than can it in my opinion be something as (depending on your
datasource)
\\\
dim columnindex as integer
for columnindex = 0 to dg.datasource.datatable.columns
if datasource.datatable.columns(i).name = mytest
exit for
next
///
I never did this, but just typed in this message as idea.

Cor
 
Hi Cor

I like the idea, unfortunately it does not work i.e. dg.datasource does not
have a member "datatable".

Geoff
 
Hi again Cor

You were, as always, on the right lines. Many thanks.

All that was needed was a few minor changes to the code:

Dim index As Integer
For index=0 To dg.DataSource.Columns.Count - 1
If dg.DataSource.Columns(index).ColumnName = mytestString Exit For
Next

i.e. The dg.DataSource returns a DataTable, in my case, so there is no need
to use the DataTable part in the original code.

Geoff
 
Back
Top