Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

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

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


and you myHandler code behind is:
C#
private void myHandler(object sender, RoutedEventArgs e)
       {
           CheckBox source = e.OriginalSource as CheckBox;
           source.IsChecked = true;
       }

I hope this help you.
Good Luck
 
Share this answer
 
Try something like below:
C#
DataGridView dgvMyGridView = this.dgvMyGridView;
               int count = dgvMyGridView.RowCount;
               for (int i = 0; i < count; i++)
               {
                   dgvMyGridView.Rows[i].SetValues(true);


               }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900