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

How to get selected rows column value/s ?

6 Answers 1498 Views
GridView
This is a migrated thread and some comments may be shown as answers.
R Shah
Top achievements
Rank 1
R Shah asked on 13 Apr 2010, 09:08 PM
Hello,
I'm looking for radGridView code for "specific column" Single or Multiple grid row selection;  Looking for similar functionality in radGriedView.
-------------------------------------------------------------------------------
GridViewRow row = GridView1.SelectedItem;
textboxCount.Text = row.Cells[2].Text + ".";
-----------------------------------------------------------------------------------

Thanks,
Raj

 

6 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 14 Apr 2010, 10:22 AM
Hello R Shah,

RadGridView.SelectedItem   will give you a direct reference to the business object associated with the row. So you don't need to read the value of the cell, you can directly read the property of the object.

Lets say we have a List of Person objects set as ItemsSource. Each row will represent a Person .
If the first column is bound to Person.FirstName and the second column is bound to Person.Age for example, we may use the following code:

var secondCellValue = ((Person)RadGridView.SelectedItem).Age
var firstCellValue = ((Person)RadGridView.SelectedItem).FirstName

In case this does not cover your scenario, just give me some more details and I will try to prepare a sample for you .

Greetings,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
R Shah
Top achievements
Rank 1
answered on 14 Apr 2010, 03:36 PM
Hello Pavel,

Thank you for your reply what I’m trying to achieve is I have given one radGridView column name “Amount” it has multiple rows  and one text box out of the grid called "textBoxTotalAmount"– functionality I’m looking for when user select single or multiple rows from gridview I want sum of selected rows of “Amount” column  into that textbox field.

Thanks,
Raj
0
Pavel Pavlov
Telerik team
answered on 14 Apr 2010, 04:34 PM
Hi R Shah,

You just need to subscribe to the selection changed event and sum the ammounts within the handler - something like :

void RadGridView1_SelectionChanged(object sender, SelectionChangeEventArgs e)
       {
           this.textBoxTotalAmount.Text =  this.RadGridView1.SelectedItems.OfType<MyBusinessObject>().Sum(i => i.Amount).ToString();
       }

* Please replace "MyBusinessObject" with the type of your busines object.

Let me know if you have troubles adapting this to your project.

Sincerely yours,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
R Shah
Top achievements
Rank 1
answered on 14 Apr 2010, 05:59 PM
Hello,

Thank you for your quick response following is kind of similar code!

XAML - 

<TextBox Name="textboxTotalAmount"/>

<telerik:RadGridView Name="radGridBankAccounts"

             <telerik:GridViewSelectColumn Name="SelectedBankAccounts" />
             <telerik:GridViewDataColumn Name="gridItemName" DataMemberBinding="{Binding Name}" Header="Item Name" Width="*" />
             <telerik:GridViewDataColumn Name="gridQty" DataMemberBinding="{Binding Qty}" Header="Qty" Width="*" />
             <telerik:GridViewDataColumn Name="gridAmount" DataMemberBinding="{Binding Amount}" Header="Amount" Width="*">
---------------- code behind

  var nwData = new BankDataDataContext();
                var MyData = nwData.usp_MyStoreProcedure("", "", "", "");

  //Grid databinding
                radGridBankAccounts.ItemsSource = (MyData);
                //Make Grid Readonly (Not Editable)
                radGridBankAccounts.IsReadOnly = true;

  
 void RadGridView1_SelectionChanged(object sender, SelectionChangeEventArgs e)
        {
//    var selectedRow = (GridViewRow)this.radGridBankAccounts.ItemContainerGenerator.ContainerFromItem(this.radGridBankAccounts.SelectedItem);

 // You have provided following code
 this.textBoxTotalAmount.Text =  this.RadGridView1.SelectedItems.OfType<MyBusinessObject>().Sum(i => i.Amount).ToString(); 
// Data is already in gridview what "MyBusinessObject" I have provide?!!!!!!!!  
        }

-----------------------------
Also I’m kind of new to radControls and this conversation going no where can you just write simple one line code in order to get just selected row; column number 3 value into string variable.

Thanks,

Raj

0
Jyothi
Top achievements
Rank 1
answered on 27 Apr 2015, 04:01 PM
Hello Pavel How I can retrieve the values to local string or integer variables from selected Telerik:RadGridView row columns or cells in  WPF XAML
0
Dimitrina
Telerik team
answered on 28 Apr 2015, 11:35 AM
Hi,

What you can do is to iterate over RadGridView.SelectedItems/RadGridView.SelectedCells collections and retrieve the specific values for the selected rows or cells.

You ca
n also refer to the online documentation on Selected items.

Regards,
Dimitrina
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
GridView
Asked by
R Shah
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
R Shah
Top achievements
Rank 1
Jyothi
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or