This is a migrated thread and some comments may be shown as answers.

Rad Grid View

4 Answers 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Morne
Top achievements
Rank 1
Morne asked on 29 Sep 2011, 02:15 PM
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

4 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 30 Sep 2011, 05:12 AM
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
0
Morne
Top achievements
Rank 1
answered on 30 Sep 2011, 09:11 AM
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
0
Emanuel Varga
Top achievements
Rank 1
answered on 30 Sep 2011, 09:13 AM
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
0
Uday
Top achievements
Rank 1
answered on 30 Sep 2011, 10:45 AM
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());
}
Tags
GridView
Asked by
Morne
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Morne
Top achievements
Rank 1
Uday
Top achievements
Rank 1
Share this question
or