Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

11 Experts available now in Live!

Get 1:1 Help Now