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
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.
Maya
the Telerik team
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
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
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
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
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
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
Please find attached the error screenshot for your reference.
Any quick help is highly solicited.
Thanks & Regards,
Hirak
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);
}
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.
Yoan
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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);
}
}
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;
Maya
Telerik
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 >>