Click to See Complete Forum and Search --> : DataRow in a DataTable...Keeping track of row index.


harrypotter28685
January 7th, 2009, 09:00 AM
Hi all,

I have a DataTable and I need to keep track of the current row index, I was not able to find any property of the datatable that does this.....

the only way i can see is to use a static index variable to do so....I was wondering if you guys know of any other better way to do this...

Thanks.

toraj58
January 7th, 2009, 09:23 AM
if you use DataGrid for representing data then handle RowEnter event of the datagrid:


private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
{
label1.Text = e.RowIndex.ToString();
}

harrypotter28685
January 7th, 2009, 09:38 AM
I cannot make use of an asp.net control here....?

DataTable is the data structure that is being used...

toraj58
January 7th, 2009, 10:11 AM
GridView can be used in win app and it differs somewhat with the GridView used in ASP.NET but their name are similar and they have common finctionality.

you should tell me how you change index of the Rows Collection. do you bind your datatable to a control like listbox, dropdownlist, gridview etc.

or itterate through the Rows in a Loop....if you use loop so the current index is the varible you use for control loop.


for (int i=0; i< dt.Rows.Count; ++i)
{
DoSomthing(); // Pseudo Method
ShowCurrentRow(i); // Pseudo Method
}