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
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.
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
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.
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
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 can also refer to the online documentation on Selected items.
Regards,
Dimitrina
Telerik
See What's Next in App Development. Register for TelerikNEXT.