Solved

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

Posted on 2010-09-17
5
1,873 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

776 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