CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2007
    Posts
    54

    DataRow in a DataTable...Keeping track of row index.

    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.

  2. #2
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: DataRow in a DataTable...Keeping track of row index.

    if you use DataGrid for representing data then handle RowEnter event of the datagrid:

    Code:
            private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
            {
                label1.Text = e.RowIndex.ToString();
            }
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  3. #3
    Join Date
    Jun 2007
    Posts
    54

    Re: DataRow in a DataTable...Keeping track of row index.

    I cannot make use of an asp.net control here....?

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

  4. #4
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: DataRow in a DataTable...Keeping track of row index.

    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.

    Code:
    for (int i=0; i< dt.Rows.Count; ++i)
    {
         DoSomthing(); // Pseudo  Method
         ShowCurrentRow(i); // Pseudo  Method
    }
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured