How to get selected rows column value/s ?

7 posts, 0 answers
  1. R Shah
    R Shah avatar
    6 posts
    Member since:
    Apr 2010

    Posted 13 Apr 2010 Link to this post

    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

     

  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 14 Apr 2010 Link to this post

    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.
  3. R Shah
    R Shah avatar
    6 posts
    Member since:
    Apr 2010

    Posted 14 Apr 2010 Link to this post

    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
  4. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 14 Apr 2010 Link to this post

    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.
  5. R Shah
    R Shah avatar
    6 posts
    Member since:
    Apr 2010

    Posted 14 Apr 2010 Link to this post

    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

  6. Jyothi
    Jyothi avatar
    1 posts
    Member since:
    Apr 2015

    Posted 27 Apr 2015 in reply to Pavel Pavlov Link to this post

    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
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 28 Apr 2015 Link to this post

    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.

     
Back to Top