简体   繁体   中英

fire the click event for each check box in GridViewCheckBoxColumn

I am using RadGridView. I have bounded a table to the grid and I have created an GridViewCheckBoxColumn and bound a bool column to it. I need to fire a method when one of the check boxes is fired in this column but none of the related events are fired by checking the check box.(note that there is not any click event in the GridViewCheckBoxColumn column and other events like MouseLeftButtonDown , PropertyChanged , TextInput are not fired by checking/unchecking the check box. the column is created by the below code:

Telerik.Windows.Controls.GridViewColumn newColumn;
if (columnInfo.typeOfColumn != null && columnInfo.typeOfColumn == typeof(bool))
{
    newColumn = new GridViewCheckBoxColumn();
    ((GridViewCheckBoxColumn)newColumn).DataMemberBinding =new Binding(columnInfo.id);
    ((GridViewCheckBoxColumn)newColumn).EditTriggers= GridViewEditTriggers.CellClick;
    ((GridViewCheckBoxColumn)newColumn).TextAlignment= TextAlignment.Center;
    ((GridViewCheckBoxColumn) newColumn).AutoSelectOnEdit = true;
}

I have not used RadGridView before but did you check the events on the grid view itself not just the column? if not check this path : http://docs.telerik.com/devtools/wpf/controls/radgridview/events/overview especially selection events section.

Since we are talking about CellEditElement, it's really CheckBox there, so we can make something like this:

code behind

private void OnChecked(object sender, RoutedEventArgs e)
{

}

private void OnUnchecked(object sender, RoutedEventArgs e)
{

}

In XAML:

<telerik:RadGridView ItemsSource="{Binding Items}" AutoGeneratingColumn="RadGridView_AutoGeneratingColumn">
    <telerik:RadGridView.Resources>
        <Style TargetType="CheckBox">
            <EventSetter Event="Checked" Handler="OnChecked"/>
            <EventSetter Event="Unchecked" Handler="OnUnchecked"/>
        </Style>
    </telerik:RadGridView.Resources>
</telerik:RadGridView>

We only must remember, that actual value will be in datatable after exit from cell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM