Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
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 is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

728 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