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

Edit a row on button click inside RADGridView control

13 Answers 647 Views
GridView
This is a migrated thread and some comments may be shown as answers.
hirak
Top achievements
Rank 1
hirak asked on 02 Mar 2011, 11:06 AM
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

13 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 02 Mar 2011, 11:27 AM
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!
0
hirak
Top achievements
Rank 1
answered on 02 Mar 2011, 11:43 AM
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
0
Maya
Telerik team
answered on 02 Mar 2011, 11:59 AM
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!
0
hirak
Top achievements
Rank 1
answered on 02 Mar 2011, 12:41 PM
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
0
Maya
Telerik team
answered on 02 Mar 2011, 12:58 PM
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!
0
hirak
Top achievements
Rank 1
answered on 03 Mar 2011, 09:13 AM
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
0
hirak
Top achievements
Rank 1
answered on 03 Mar 2011, 09:27 AM
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
0
hirak
Top achievements
Rank 1
answered on 03 Mar 2011, 09:30 AM
Hi,

Please find attached the error screenshot for your reference.

Any quick help is highly solicited.

Thanks & Regards,
Hirak
0
Bertha
Top achievements
Rank 1
answered on 23 Apr 2013, 06:34 PM
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);
}

0
Yoan
Telerik team
answered on 24 Apr 2013, 07:00 AM
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.

0
Raj
Top achievements
Rank 1
answered on 22 Oct 2013, 12:52 PM
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);      
            }
        }
0
Maya
Telerik team
answered on 23 Oct 2013, 06:54 AM
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 >>
0
Mark
Top achievements
Rank 1
answered on 31 Oct 2014, 08:12 PM
Thank you Maya that was perfect!
Tags
GridView
Asked by
hirak
Top achievements
Rank 1
Answers by
Maya
Telerik team
hirak
Top achievements
Rank 1
Bertha
Top achievements
Rank 1
Yoan
Telerik team
Raj
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Share this question
or