Find the control in Datagrid

Posted by Venkatesh under WPF on 5/8/2012 | Points: 10 | Views : 34385 | Status : [Member] | Replies : 3
Hi,

I am adding one Checkbox control in datagrid. I want to find this control in code behind?

My Source code:

<DataGrid Background="White" Height="262" Name="GrvTrade" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" >

<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>

<CheckBox x:Name="chkstatus" Click="chkstatus_Click" Checked="chkstatus_Checked" IsChecked="{Binding Path = ForDisplay , Mode = TwoWay}"/>

</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Path=Name}" Header="Name"/>

</DataGrid.Columns>

</DataGrid>

Thanks,
Venkatesh.P




Responses

Posted by: Vuyiswamb on: 5/8/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Look at this

 // Iterates through the rows of the GridView control

foreach (GridViewRow row in GrvTrade.Rows)
{
// Selects the checked items from the gridview
CheckBox chkstatus= ((CheckBox )row.FindControl("chkstatus"));

if(chkstatus.Checked)
{
// do what ever you want

}


Thank you for posting at Dotnetfunda
[Administrator]

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Venkatesh on: 5/8/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Vuyiswamb,
Thanks for replying,

The code which you gave me, i am getting error at GrvTrade.Rows.It is a datagrid control in wpf.

Thanks,
Venkatesh.P


Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 5/8/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
ahh sorry i thought it was asp.net , here is a WPF/Silverlight code

http://manaspatnaik.com/blog/index.php/technology/silverlight-4/accessing-controls-in-datagrid-columnheader-silverlight/877

Thank you for posting at Dotnetfunda
[Administrator]

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response