Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-09-17
5
Medium Priority
?
2,043 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

610 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