Solved

Radiobutton click or checked events firing automitically when datagrid cell is selected in WPF

Posted on 2010-09-17
5
1,812 Views
Last Modified: 2013-11-12
I have a radiobutton in my datagrid(WPF).when i check the radiobutton, in code-behind page under radiobutton_click event i am doing some operations.the problem is when i select the checkbox cell of the datagrid,the radiobutton_click event is firing automitically. I want to trigger the radio_button click event only when i check the radiobutton.how to  prevent  the radiobutton_click event when i select radiobutton cell in datagrid.

code
--------

<Custom:DataGrid x:Name="dgCheckReceiptReport" Margin="-3.693,-4.283,6,139"  AutoGenerateColumns="False" LoadingRow="dgCheckReceiptReport_LoadingRow" CanUserAddRows="False">
                                        <Custom:DataGrid.Columns>
                                        <Custom:DataGridTemplateColumn Header="Account check off">
                                            <Custom:DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <RadioButton Name="rdAccountCheckOff" Focusable="False" IsChecked="{Binding Path = IsOpen, TargetNullValue = false}" Click="rdAccountCheckOff_Click"></RadioButton>
                                                </DataTemplate>
                                            </Custom:DataGridTemplateColumn.CellTemplate>
                                        </Custom:DataGridTemplateColumn>
                                        <Custom:DataGridTextColumn Header="Data Received" Binding="{Binding Path = ReceivedDate}" Width="107"/>
                                            <Custom:DataGridTextColumn Header="ID NBR" Binding="{Binding Path = FrbId}" Width="130"/>
                                            <Custom:DataGridTextColumn Header="Division" Binding="{Binding Path = Division}" Width="173"/>
                                            <Custom:DataGridTextColumn Header="Check NBR" Binding="{Binding Path = CheckNumber}" Width="150"/>
                                            <Custom:DataGridTextColumn Header="Amount" Binding="{Binding Path = Amount}" Width="140"/>
                                            <Custom:DataGridTextColumn Header="Received From" Binding="{Binding Path = ReceivedFrom}" Width="150"/>
                                            <Custom:DataGridTextColumn Header="Payment For" Binding="{Binding Path = PaymentFor}" Width="150"/>
                                        </Custom:DataGrid.Columns>
                                    </Custom:DataGrid>

code-behind
----------------

 private void rdAccountCheckOff_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (e.OriginalSource == null)
                    return;


                FundsReceiptBatchDetails checkReceiptreportfbr = dgCheckReceiptReport.CurrentItem as FundsReceiptBatchDetails;

                if (checkReceiptreportfbr.IsOpen)
                {
                    if (FundsReceiptStatus.Inprocess.ToString() == FundsReceiptBatchDetailsBo.Ins.GetFundsReceiptStatus(checkReceiptreportfbr.FrbId))
                    {
                        LoadCheckReceiptReportData();
                        txbCheckReceiptReportMessage.Text = Constants.FundsReceiptIsAlreadyProcessedByAccountingDepartmentRepresentative;
                        return;
                    }
                       
                    checkReceiptreportfbr.ReceiptStatus = (FundsReceiptBatchDetailsBo.Ins.GetFundsReceiptStatus(checkReceiptreportfbr.FrbId)
                        == FundsReceiptStatus.Open.ToString() ? FundsReceiptStatus.Validated.ToString() :
                        FundsReceiptStatus.Inprocess.ToString());

                    checkReceiptreportfbr.ModifiedBy = txbUsername.Text;

                    checkReceiptreportfbr.ModifiedDate = DateTime.Now;

                    FundsReceiptBatchDetailsBo.Ins.UpdateFundsReceiptStatus(checkReceiptreportfbr);

                    LoadCheckReceiptReportData();

                    txbCheckReceiptReportMessage.Text = Constants.FundsReceiptIsSucessfullyVerified;
                }
            }
            catch (Exception ex)
            {
               
                throw ex;
            }
           
        }
0
Comment
Question by:kravindra
  • 3
  • 2
5 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33702675
It would be better practice if you move the code to your model in the setter rather than have an event like this. This would take care of your event problem also.

But said that... to solve this issue use the Checked and UnChecked events of radio button
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33702687

<Custom:DataGrid x:Name="dgCheckReceiptReport" Margin="-3.693,-4.283,6,139"  AutoGenerateColumns="False" LoadingRow="dgCheckReceiptReport_LoadingRow" CanUserAddRows="False">

                                        <Custom:DataGrid.Columns>

                                        <Custom:DataGridTemplateColumn Header="Account check off">

                                            <Custom:DataGridTemplateColumn.CellTemplate>

                                                <DataTemplate>

                                                    <RadioButton Name="rdAccountCheckOff" Focusable="False" IsChecked="{Binding Path = IsOpen, TargetNullValue = false}" Checked="rdAccountCheckOff_Click" Unchecked="rdAccountCheckOff_Click"></RadioButton>

                                                </DataTemplate>

                                            </Custom:DataGridTemplateColumn.CellTemplate>

                                        </Custom:DataGridTemplateColumn>

                                        <Custom:DataGridTextColumn Header="Data Received" Binding="{Binding Path = ReceivedDate}" Width="107"/>

                                            <Custom:DataGridTextColumn Header="ID NBR" Binding="{Binding Path = FrbId}" Width="130"/>

                                            <Custom:DataGridTextColumn Header="Division" Binding="{Binding Path = Division}" Width="173"/>

                                            <Custom:DataGridTextColumn Header="Check NBR" Binding="{Binding Path = CheckNumber}" Width="150"/>

                                            <Custom:DataGridTextColumn Header="Amount" Binding="{Binding Path = Amount}" Width="140"/>

                                            <Custom:DataGridTextColumn Header="Received From" Binding="{Binding Path = ReceivedFrom}" Width="150"/>

                                            <Custom:DataGridTextColumn Header="Payment For" Binding="{Binding Path = PaymentFor}" Width="150"/>

                                        </Custom:DataGrid.Columns>

                                    </Custom:DataGrid>

Open in new window

0
 

Author Comment

by:kravindra
ID: 33705073
In my requirement, when user check the radiobutton,then i will remove that checked row from datagrid.here i didn't have option to raise the radiobutton uncheck event.  using setter block i can't write all my presentation logic in it.so i think it's not possible with setter block. Is there is anyway to solve this issue?


0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 33706838
you dont need the unchecked event then you can do just with Checked event in the radio button.
<Custom:DataGrid x:Name="dgCheckReceiptReport" Margin="-3.693,-4.283,6,139"  AutoGenerateColumns="False" LoadingRow="dgCheckReceiptReport_LoadingRow" CanUserAddRows="False">

                                        <Custom:DataGrid.Columns>

                                        <Custom:DataGridTemplateColumn Header="Account check off">

                                            <Custom:DataGridTemplateColumn.CellTemplate>

                                                <DataTemplate>

                                                    <RadioButton Name="rdAccountCheckOff" Focusable="False" IsChecked="{Binding Path = IsOpen, TargetNullValue = false}" Checked="rdAccountCheckOff_Click"></RadioButton>

                                                </DataTemplate>

                                            </Custom:DataGridTemplateColumn.CellTemplate>

                                        </Custom:DataGridTemplateColumn>

                                        <Custom:DataGridTextColumn Header="Data Received" Binding="{Binding Path = ReceivedDate}" Width="107"/>

                                            <Custom:DataGridTextColumn Header="ID NBR" Binding="{Binding Path = FrbId}" Width="130"/>

                                            <Custom:DataGridTextColumn Header="Division" Binding="{Binding Path = Division}" Width="173"/>

                                            <Custom:DataGridTextColumn Header="Check NBR" Binding="{Binding Path = CheckNumber}" Width="150"/>

                                            <Custom:DataGridTextColumn Header="Amount" Binding="{Binding Path = Amount}" Width="140"/>

                                            <Custom:DataGridTextColumn Header="Received From" Binding="{Binding Path = ReceivedFrom}" Width="150"/>

                                            <Custom:DataGridTextColumn Header="Payment For" Binding="{Binding Path = PaymentFor}" Width="150"/>

                                        </Custom:DataGrid.Columns>

                                    </Custom:DataGrid>

Open in new window

0
 

Author Closing Comment

by:kravindra
ID: 33825645
I got the solution
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now