Edit a row on button click inside RADGridView control

14 posts, 0 answers
  1. hirak
    hirak avatar
    36 posts
    Member since:
    Feb 2011

    Posted 02 Mar 2011 Link to this post

    Hi,

    I want to edit a row on click of a Button which will be placed inside the RadGridView control and make that particular row highlighted.

    Is there any way, in which I can achieve this functionality.

    Early, code sample to this solution will be highly appreciated.

    Thanks & Regards,
    Hirak
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Mar 2011 Link to this post

    Hello hirak,

    You may handle the Click event of the button and find its corresponding row by the ParentOfType<T> extension method. Afterwards, you may either set the Background property of the row or set it as selected.

     

    All the best,
    Maya
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. hirak
    hirak avatar
    36 posts
    Member since:
    Feb 2011

    Posted 02 Mar 2011 Link to this post

    Hi,

    Could you please assist me with a sample code which will be usefull to be as I am completely new to this control.

    Thanks & Regards,
    Hirak
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Mar 2011 Link to this post

    Hi hirak,

    In case the definition of the column is as follows:

    <telerik:GridViewColumn>
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton Content="SelectTheRow" Click="RadButton_Click" />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                    <telerik:GridViewColumn>

    The Click event may be handled like:
    private void RadButton_Click(object sender, RoutedEventArgs e)
            {
                var button = sender as RadButton;
                var row = button.ParentOfType<GridViewRow>();
                if(row != null)
                {
                    row.IsSelected = true; 
              //or set its background:
              //row.Background = new SolidColorBrush(Colors.Tomato);      
                }
            }

     

    Kind regards,
    Maya
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  5. hirak
    hirak avatar
    36 posts
    Member since:
    Feb 2011

    Posted 02 Mar 2011 Link to this post

    Hi,

    This code was usefull.

    Now, I want to fetch the values of the records which gets highlighted on click of the button which is placed inside the RadGridView control.

    How can I achieve this functionality.

    Any quick code sample will be highly usefull as I am completely new in this control.

    Thanks & Regards,
    Hirak
  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Mar 2011 Link to this post

    Hi hirak,

    If you chose the case of selecting the row, you may use directly the SelectedItem property of the grid to get the corresponding item. Otherwise, you may get the item as follows:

    private void RadButton_Click_1(object sender, RoutedEventArgs e)
            {
                var button = sender as RadButton;
                var row = button.ParentOfType<GridViewRow>();
                if (row != null)
                {
                    row.Background = new SolidColorBrush(Colors.Tomato);
                    var item = row.Item as Club;
                }
            }

    In this case Club is the business object of the grid.
     

    Greetings,
    Maya
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  7. hirak
    hirak avatar
    36 posts
    Member since:
    Feb 2011

    Posted 03 Mar 2011 Link to this post

    Hi,

    Selection of row on click of button is behaving in a weird way.

    It is highlighting different rows rather than the one on which the button is placed and clicked.

    Please, update if the code which have send is correct.

    Thanks & Regards,
    Hirak
  8. hirak
    hirak avatar
    36 posts
    Member since:
    Feb 2011

    Posted 03 Mar 2011 Link to this post

    Hi,

    The highlighting of rows is happening every 30th column and sometimes after every 19th or 6th column.

    Please clarify, what is the cause of this behaviour.

    Any quick solution to this issue will be highly appreciated.

    Thanks & Regards,
    Hirak
  9. hirak
    hirak avatar
    36 posts
    Member since:
    Feb 2011

    Posted 03 Mar 2011 Link to this post

    Hi,

    Please find attached the error screenshot for your reference.

    Any quick help is highly solicited.

    Thanks & Regards,
    Hirak
  10. Bertha
    Bertha avatar
    95 posts
    Member since:
    Aug 2012

    Posted 23 Apr 2013 Link to this post

    I used the same code. When I clicked on the button, the outline of that row will become red.  Then, I click on another row, the new row will have outline as red but the previous clicked row will have background red. How can I remove the background red from previous clicked button row? The IsSelected is working correctly.
    var btnChange = sender as RadButton;
    var row = btnChange.ParentOfType<GridViewRow>();
    if (row != null)
    {
        row.IsCurrent = true;
        row.IsSelected = true;
        row.Background = new SolidColorBrush(Colors.Red);
    }

  11. Yoan
    Admin
    Yoan avatar
    1214 posts

    Posted 24 Apr 2013 Link to this post

    Hi Bertha,

    If you want to modify the appearance of the selected row, you can predefine its template using Microsoft Expression Blend. There you should modify the Border element named Background_Selected in the way you need. I can suggest you to check this help article for a reference.

    I hope this information helps.


    Kind regards,
    Yoan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  12. Raj
    Raj avatar
    2 posts
    Member since:
    Oct 2013

    Posted 22 Oct 2013 Link to this post

    Hi maya how to get the contents of items to string individualy 
    below i get the row.item content like this {King= 20 , Name = burg}
    i need to get it to string individually
    so that i can edit the contents in a pop up window
    some wat like this messagebox.show{king=20}/
     private void btnEdit_Click(object sender, RoutedEventArgs e)
            {
                var button = sender as RadButton;
                var row = button.ParentOfType<GridViewRow>();
                if (row != null)
                {
                    
                    row.IsSelected = true;
                    row.Background = new SolidColorBrush(Colors.Tomato);
                    var item = row.Item;
                    //or set its background:
                    //row.Background = new SolidColorBrush(Colors.Tomato);      
                }
            }
  13. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 23 Oct 2013 Link to this post

    Hello Raj,

    Based on the info you provided, I guess "King" and "Name" are properties of your business object - let's say "Person". Once you cast the item - var person = row.Item as Person;, you will then be able to get its properties like var name = person.Name; 

    Regards,
    Maya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  14. Mark
    Mark avatar
    16 posts
    Member since:
    Sep 2012

    Posted 31 Oct 2014 in reply to Maya Link to this post

    Thank you Maya that was perfect!
Back to Top