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

Accessing controls in rows

1 Answer 38 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lars Berg
Top achievements
Rank 1
Lars Berg asked on 22 Jul 2008, 12:44 PM
Hi,
I have some questions - I've looked in the examples but couldn't find the answers. Maybe you should extend your "Columns" example with this.

I have a Datagrid bound to a datasource.
In one column I have a unbound Button
In another column I have a unbound ComboBox

Both inserted via a ControlTemplate

1) When clicking the Button how do I know which row was clicked?
I use the DataGrid.CurrentRecord property - and that seems to work ok. Through casts I can get the primaryID of the row.
But is that the preferred way to do it. And is it a reliable way?

2) In the button click event: How do I access the ComboBox in the current row. I've tried doing it through the CurrentRecord property . but seems to focus more on the datasource rows - and not on the rendered rows and cells. How do I do that ?

3) Do you ship documentation with the Release 1.0 at the end of July ?

1 Answer, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 24 Jul 2008, 03:30 PM
Hi Lars Berg,

Using the CurrentRecord property is a legitimate way of getting the current data record but you may try another approach for your scenario. Since every button is part of a GridViewRow you use can the button's DataContext property to get the DataRecord that you need.

The answer to your second question is trickier since there are two solutions. The first one is to place both the Button and the ComboBox in a single unbound column. In this case you can easily find your ComboBox. If you really need to have two unbound columns you can try the second approach which involves traversal of the visual tree. I wouldn't recommend this approach becase it is dependent on a particular visual structure that might change in the future. Since there is some code involved in implementing both solution I have created a sample project that illustates both approaches (you can find it attached to this post).

The first approach uses a custom RoutedCommand to execute the logic and to get access to the ComboBox.
The method that executes the command is called "CustomCommandExecute".

The second approach uses a simple handler, called "Button_Click", for the Click event. In that handler we use the FindElement method to find the needed ComboBox and execute the custom logic.

We have just released version 1.0 of our WPF suite which ships with documentation and API reference.

Kind regards,
Milan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Lars Berg
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or