Events from controls in a DataGridTemplateColumn

Posted by: bdwest on 7 August 2017, 6:42 am EST

  • Posted 7 August 2017, 6:42 am EST

     I have a group of 5 radio buttons in each cell of a column within a datagrid as shown below.  When a button is checked it toggles one of five boolean values in my class to true.  That part works fine. I also need to generate a event when any of the 5 radio buttons is changed.  Since the radio buttons are embeded in the DataTemplate I can seem to access any of the radio button events.  Can someone tell me how to do this, assuming it is possible.


     Thanks


     Brian


     <c1grid:DataGridTemplateColumn Header="     Soil   Moisture" Width="100" EditOnSelection="True" >
           <c1grid:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
             <StackPanel Height="auto" HorizontalAlignment="Left" VerticalAlignment="Top" Width="auto" Orientation="Horizontal" RenderTransformOrigin="0.5,0.5">
                        <RadioButton IsChecked="{Binding Path=SoilM_VeryLow, Mode=TwoWay}" HorizontalAlignment="Left" VerticalAlignment="Top" Content="" Background="#FFFF0000" x:Name="RB_VeryLow" Foreground="#FFFF0000" BorderBrush="#FFFF0000" BorderThickness="1,1,1,5" ToolTipService.ToolTip="Very Low"/>
              <RadioButton IsChecked="{Binding Path=SoilM_Low, Mode=TwoWay}" HorizontalAlignment="Left" VerticalAlignment="Top" Content="" Foreground="#FFF5E502" x:Name="RB_Low" Background="#FFF5E502" BorderBrush="#FFF5E502" ToolTipService.ToolTip="Low"/>
              <RadioButton IsChecked="{Binding Path=SoilM_Ok, Mode=TwoWay}" HorizontalAlignment="Left" VerticalAlignment="Top" Content="" x:Name="RB_OK" Background="#FF00FF00" BorderBrush="#FF00FF00" Foreground="#FF00FF00" ToolTipService.ToolTip="OK"/>
              <RadioButton IsChecked="{Binding Path=SoilM_High, Mode=TwoWay}" HorizontalAlignment="Left" VerticalAlignment="Top" Content="" Foreground="#FF10E8F5" Background="#FF10E8F5" BorderBrush="#FF10E8F5" x:Name="RB_High" ToolTipService.ToolTip="High"/>
              <RadioButton IsChecked="{Binding Path=SoilM_VeryHigh, Mode=TwoWay}" HorizontalAlignment="Left" VerticalAlignment="Top" Content="" Foreground="#FF0000FF" BorderBrush="#FF0000FF" Background="#FF0000FF" x:Name="RB_VeryHigh" ToolTipService.ToolTip="Very High"/>
              </StackPanel>  
            </DataTemplate>
           </c1grid:DataGridTemplateColumn.CellTemplate>
            
          </c1grid:DataGridTemplateColumn>

  • Replied 7 August 2017, 6:42 am EST

    Thanks, I had not thought about that option.

  • Replied 7 August 2017, 6:42 am EST

    Hi Brian,


    I believe the simplest way to do that is to put the content of the cell(The radio buttons) into a usercontrol, then each cell will have this user control as the template of the cell. As you can see you can put the logic of the radio buttons in the user control code behind.


    Regards,


    Alvaro.

  • Replied 9 June 2019, 11:19 pm EST

    I am having problems with DataGrid celltemplate and headertemplate. I have created many datagridtemplatecolumns in the code behind and when I apply both templates my data is not showing up properly.

    Is there any sample for this.
    A dataGrid build in c# with a user control in the CellTemplate and a user control in the HeaderTemplate.
    When I apply only CellTemplate my data is fine but when I apply both templates my data is no good.

    plz help

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels