what is the best way to identify first row in the following code?
foreach(DataRow row in myrows)
{
if (first row )
{
...do this...
}
else
{
....process other than first rows..
}
}
what is the best way to identify first row in the following code?
foreach(DataRow row in myrows)
{
if (first row )
{
...do this...
}
else
{
....process other than first rows..
}
}
You can use a boolean flag for this:
bool isFirst = true;
foreach(DataRow row in myrows)
{
if (isFirst)
{
isFirst = false;
...do this...
}
else
{
....process other than first rows..
}
}
you could just use a for loop instead
for(int i = 0; i < myrows.Count; i++)
{
DataRow row = myrows[i];
if (i == 0) { }
else { }
{
Maybe something like this?
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Index == 0)
{
//...
}
else
{
//...
}
}
Use a int to loop through the collection.
for (int i =0; i < myDataTable.Rows.Count;i++)
{
if (i ==0)
{
//first row code here
}
else
{
//other rows here
}
}
First convert the DataRow to DataRowView:
How Can Convert DataRow to DataRowView in c#
and after that:
foreach (DataRowView rowview in DataView)
{
if (DataRowView.Table.Rows.IndexOf(rowview.Row) == 0)
{
// bla, bla, bla...
}
}