kravindra
asked on
How to read a checkbox value in a datagrid in WPF
I have datagrid. it contain DataGridCheckBoxColumn . I am allowing the user to check or uncheck the checkbox.I have button which is out side of the datagrid. in the button_click eventhandler I want to read datagrid checkbox value.
here my datagrid contains number of rows . i want to read checkbox values from all the rows.
Here MyDatagrid Xaml code
-------------------------- ---
<Custom:DataGrid x:Name="dgDivision" AutoGenerateColumns="False " CanUserAddRows="False" Grid.ColumnSpan="5" Grid.Column="1" Margin="12.803,199,22,146" >
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Header="FrbId" Binding="{Binding Path = FrbId}" Visibility="Hidden" />
<Custom:DataGridCheckBoxCo lumn Header="Select" IsReadOnly="False" Width="60" />
<Custom:DataGridTextColumn Header="Received From" Binding="{Binding Mode=TwoWay, Path = ReceivedFrom}" Width="150" />
<Custom:DataGridTextColumn Header="Receive Date" Binding="{Binding Mode=TwoWay, Path = ReceivedDate}" Width="100" />
<Custom:DataGridTextColumn Header="Check #" Binding="{Binding Mode=TwoWay, Path = CheckNumber}" Width="150" />
<Custom:DataGridTextColumn Header="Amount" Binding="{Binding Mode=TwoWay, Path = Amount}" Width="100" />
<Custom:DataGridTextColumn Header="Payment For" Width="150" Binding="{Binding Mode=TwoWay, Path = PaymentFor}" />
</Custom:DataGrid.Columns>
</Custom:DataGrid>
here my datagrid contains number of rows . i want to read checkbox values from all the rows.
Here MyDatagrid Xaml code
--------------------------
<Custom:DataGrid x:Name="dgDivision" AutoGenerateColumns="False
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn
<Custom:DataGridCheckBoxCo
<Custom:DataGridTextColumn
<Custom:DataGridTextColumn
<Custom:DataGridTextColumn
<Custom:DataGridTextColumn
<Custom:DataGridTextColumn
</Custom:DataGrid.Columns>
</Custom:DataGrid>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In other terms:
You always need objects that the datagrid can bind to, also for a check box column. You need a boolean property you can bind your check box column to. Then just query your objects to see if they were checked.
You should not access the data grid cells in any way to get values - that is ugly :-)
You always need objects that the datagrid can bind to, also for a check box column. You need a boolean property you can bind your check box column to. Then just query your objects to see if they were checked.
You should not access the data grid cells in any way to get values - that is ugly :-)
ASKER
I got the solution
Assuming that the prpperties FrbId,ReceivedFrom,Receive
You can try the following code in button_Click event.
foreach(Transaction txn in TransactionList)
{
bool bChkboxValue = txn.FrbId;
.....
....
}
Is this what you want?
Thx!
Swaps....