How to get column index?

I can look up the column name as below
DT.Select("[math]=‘Pass’").Count

But I want to find the column index
Tell me how to do it

Do you know the column name before whose index you want?

You have to use for each row, then make a counter and increase it in each loop.

KR,

Pablo

1 Like

@Sunny
DT.Columns("[ColumnName]").Ordinal will give you an integer value representing the column index

2 Likes

Hi @SunnyK,

Welcome to the community!

If you do not know the column names, you can always loop through the Columns to get the name and index. Sample give below.

ColumnIndex.xaml (6.6 KB)

@SunnyK

If you the column name use this

DataTable.Columns.IndexOf(“ColumnName”).ToString

3 Likes