Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14679 |

    When the user selects a row in the Grid control, I would like to be to read the index of the selected row.

    Either C# or VB.NET would be great.

    Thanks,

    Milo

    Imported from legacy forums. Posted by Milo (had 2132 views)

    User (Old forums)
    Member
    Post count: 23064

    You can use the DataRows collection to obtain this information :

    in Form_Load :

    foreach( Cell cell in dataRowTemplate1.Cells )
    {
    cell.Click += new EventHandler(cell_Click);
    }

    Event handler :

    private void cell_Click(object sender, EventArgs e)
    {
    Xceed.Grid.DataRow row = gridControl1.CurrentRow as Xceed.Grid.DataRow;
    if( row != null)
    {
    int index = gridControl1.DataRows.IndexOf( row );
    }
    }

    Depending of the event to which you have subscribed, you may need to do the preceding safe type cast, because the CurrentRow could be something other then a DataRow. In this event however, this could all be omitted and have only the int index line, for CurrentRow is always a DataRow :

    int index = gridControl1.DataRows.IndexOf( ( Xceed.Grid.DataRow )gridControl1.CurrentRow );

    Imported from legacy forums. Posted by André (had 3051 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.