0

次のコードの最初の行を識別するための最良の方法は何ですか?

foreach(DataRow row in myrows)
{

if (first row )
{
...do this...
}
else
{
....process other than first rows..
}
}
4

5 に答える 5

5

これにはブールフラグを使用できます。

bool isFirst = true;

foreach(DataRow row in myrows)
{
    if (isFirst)
    {
        isFirst = false;
        ...do this...
    }
    else
    {
        ....process other than first rows..
    }
}
于 2010-03-16T17:21:18.797 に答える
3

代わりにforループを使用できます

for(int i = 0; i < myrows.Count; i++) 
{
    DataRow row = myrows[i];
    if (i == 0) { }
    else { }
{
于 2010-03-16T17:21:14.710 に答える
2

多分このようなもの?

    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        if (row.Index == 0)
        {
            //...
        }
        else
        {
            //...
        }
    }
于 2010-03-16T17:23:43.893 に答える
0

intを使用して、コレクションをループします。

for (int i =0; i < myDataTable.Rows.Count;i++)
{
    if (i ==0)
    {
       //first row code here
    }
    else
    {
       //other rows here
    }
}
于 2010-03-16T17:25:14.547 に答える
0

まず、DataRowをDataRowViewに変換します。

C#でDataRowをDataRowViewに変換する方法

それとその後:

    foreach (DataRowView rowview in DataView)
{
    if (DataRowView.Table.Rows.IndexOf(rowview.Row) == 0)
    {
        // bla, bla, bla... 
    }
}
于 2015-02-22T15:41:03.310 に答える