Rad Grid View

5 posts, 0 answers
  1. Morne
    Morne avatar
    2 posts
    Member since:
    Aug 2010

    Posted 29 Sep 2011 Link to this post

    Hi,

    I have a RAD Gridview in my form and it loads the invoices that has the status "Due".

    What I now want to do is when the user clicks on the row of the invoice he wants to view it should get the selected items Index value in my case a value in the "ID" column.

    How do I get the selected row's "ID" value from the gridview?

    Thanks
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 30 Sep 2011 Link to this post

    Hello,

    You could get the data bound item for the current row, like so:
    if (radGridView1.CurrentRow == null)
    {
        return;
    }
     
    var data = radGridView1.CurrentRow.DataBoundItem as Invoice;
    var id = data.Id;
    // do what you need here

    or if you already have that column in the grid
    if (radGridView1.CurrentRow == null || !radGridView1.Columns.Contains("Id"))
    {
        return;
    }
     
    var value = radGridView1.CurrentRow.Cells["Id"].Value;
    if (value == null)
    {
        return;
    }
     
    var id = Convert.ToInt32(value);
    // do what you need here

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Morne
    Morne avatar
    2 posts
    Member since:
    Aug 2010

    Posted 30 Sep 2011 Link to this post

    Hi,

    I am still new to c# and RAD,

    what will the event name be for when the radGridView1 changes the selected row?

    will it be  

    private void radGridView1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
            {
            }

    or what will it be?

    Thanks
  5. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 30 Sep 2011 Link to this post

    Hello again,

    The events fired for current row changed is CurrentRowChanging and CurrentRowChanged.

    Glad to be able to help,

    If you have any more questions please just let me know, and if the question has been solved, please mark the question as answered, so that others can find the answers to their questions faster.

    Best Regards,
    Emanuel Varga


    WinForms MVP
  6. Uday
    Uday avatar
    7 posts
    Member since:
    Sep 2011

    Posted 30 Sep 2011 Link to this post

    hello morne,

    Your question makes me to think in variety of possibilities as you need to mention some more details, to get better answer.

    But by assumption, i would like to add some idea.
     Am assuming that you have a set of invoices which are in the status 'DUE' and it has a column called "ID" and you would want to get the value of the ID column when an user selects  a record (row), then you can use the click event  or mouse click event
    It can be in the following way. i have used row index and column index as 0. you can use the name of the column instead.
      
    private void radGridView1_Click(object sender, EventArgs e)
     {
    MessageBox.Show(radGridView1.SelectedRows[0].Cells[0].Value.ToString());
    }
Back to Top
UI for WinForms is Visual Studio 2017 Ready