Click here to Skip to main content
15,903,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys
i have a data grid with columns Called Taxes i made a style to this Column to manage me Fire Event (Text Changed) when any thing Typed in this Column bu user , i succeed in doing that but now when i type in the column it fire the Event As i Want , the problem is the data i typed in the column does not Appear only if the Column is in editable mode else the data disappear , how can i solve that
thanks in advanced


My code :-

HTML
<datagridtextcolumn loc:translate.uid="1629" header="{loc:Translate   Taxes}" width="Auto" xmlns:loc="#unknown">
                    <datagridtextcolumn.editingelementstyle>
                        <Style TargetType="TextBox">
                            <setter>
                                <setter.property>
                                    Text
                                </setter.property>
                                <setter.value>
                                    <binding>
                                        <binding.path>Tax</binding.path>
                                        <binding.mode>TwoWay</binding.mode>
                                        <binding.updatesourcetrigger>PropertyChanged</binding.updatesourcetrigger>
                                    </binding>
                                </setter.value>
                            </setter>
                            <eventsetter event="TextChanged" handler="Txt_Tax_TextChanged" />                            
                        </Style>
                    </datagridtextcolumn.editingelementstyle>
                </datagridtextcolumn>



C#
private void Txt_Tax_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                this.UpdateTotal();
            }
            catch
            {

            }
        }
Posted
Updated 3-Nov-11 3:51am
v2
Comments
Yasser El Shazly 3-Nov-11 10:33am    
i think there is A problem in the Visual tree , or some thing make it does not see the data is right if so can be resolved ..?

1 solution

You should bind your TextColumn to a property in the codebehind/viewmodel. Then in the setter for that property you can increase the taxes appropriately. Something like this :-

XML
<datagridtextcolumn binding="{Binding" path="Tax}/"></datagridtextcolumn>


and in your code behind

C#
decimal tax;
decimal totalTaxes;
public decimal Tax
        {
            get { return tax; }
            set
            {
                if (tax == value) return;
                tax = value;
                totalTaxes += value;
                OnPropertyChanged("Tax");
            }
}


Hope that helps
 
Share this answer
 
Comments
Yasser El Shazly 3-Nov-11 10:43am    
i want to make the binding direct to the Text , in order to any changes on the data immediately bonded to the data table attached to the data grid without needing to press enter after editing to affect the data table

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900