在表单中加载在datagridview中选中的所有复选框defaullty [英] In the form load all checkbox defaullty selected in datagridview

查看:104
本文介绍了在表单中加载在datagridview中选中的所有复选框defaullty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在datagridcview中我有两列Checkbox和Date。



在表单加载中我想在datagridview中选中所有复选框defaullty。



为此我怎样才能使用csharp。





问候,

Narasiman P.

In datagridcview i have two columns Checkbox and Date.

In the form load i want all checkbox defaullty selected in datagridview.

For that how can i do using csharp.


Regards,
Narasiman P.

推荐答案

嗨。如果您使用WPF,您可以执行以下操作:



您的xaml必须如下:

Hi. If you work with WPF you can do following:

Your xaml must be like:
<DataGrid>
    <DataGrid.Columns>
        <DataGridCheckBoxColumn >
            <DataGridCheckBoxColumn.ElementStyle>
                <Style TargetType="{x:Type CheckBox}">
                    <EventSetter Event="CheckBox.Loaded" Handler="myHandler"/>
                </Style>
            </DataGridCheckBoxColumn.ElementStyle>
        </DataGridCheckBoxColumn>
    </DataGrid.Columns>
</DataGrid>





你背后的myHandler代码是:



and you myHandler code behind is:

private void myHandler(object sender, RoutedEventArgs e)
       {
           CheckBox source = e.OriginalSource as CheckBox;
           source.IsChecked = true;
       }



我希望这对你有所帮助。

祝你好运


I hope this help you.
Good Luck


尝试像下面:

Try something like below:
DataGridView dgvMyGridView = this.dgvMyGridView;
               int count = dgvMyGridView.RowCount;
               for (int i = 0; i < count; i++)
               {
                   dgvMyGridView.Rows[i].SetValues(true);


               }


这篇关于在表单中加载在datagridview中选中的所有复选框defaullty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆