Q: Determing in a column in a datagrid

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
 
C

Cor Ligthert

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
 
G

Geoff Jones

Hi Cor

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

Geoff
 
G

Geoff Jones

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top