Solved

How to read a checkbox value in a datagrid in WPF

Posted on 2010-08-17
4
2,323 Views
Last Modified: 2013-11-12
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:DataGridCheckBoxColumn 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>
0
Comment
Question by:kravindra
4 Comments
 
LVL 18

Accepted Solution

by:
Anil Golamari earned 500 total points
ID: 33458638
0
 
LVL 10

Expert Comment

by:k_swapnil
ID: 33461580
Hi Ravi,

Assuming that the prpperties FrbId,ReceivedFrom,ReceivedDate... etc are in class "Transaction"  its collection "TransactionList" is acting as ItemSource for the grid.
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....
0
 
LVL 1

Expert Comment

by:JensMig
ID: 33571194
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 :-)
0
 

Author Closing Comment

by:kravindra
ID: 33702502
I got the solution
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question