When I change the value of a Combobox they all change

Asked

Viewed 96 times

0

I have a database with two tables, Tab1 and Tab2. On Tab 1 I have Cd_tab1 and Nm_object.
In Tab2 I have Cd_tab2, Cd_tab1.
The two are related.
In my project I have 4 Combobox, all must represent the value of Cd_tab2, but each will save a new Cd_tab2(Ex: First Cmb = Cd_tab2(1), Second Cmb = Cd_tab2(2) etc...
The problem I’m having is that when I change the value of one cmb in the project all the others change together.

Code XAML:

<ComboBox x:Name="btCmbAtkBaAtr2" HorizontalAlignment="Left" Margin="0,79,0,0" 
            VerticalAlignment="Top" Width="50" DisplayMemberPath="Nm_Objeto" 
            ItemsSource="{Binding Source={StaticResource Tab1ViewSource}}" 
            SelectedValuePath="Cd_Tab1" 
            SelectedValue="{Binding Cd_Tab1, Source={StaticResource Tab2ViewSource}}"/>
<ComboBox x:Name="btCmbAtkBaAtr2" HorizontalAlignment="Left" Margin="0,79,0,0" VerticalAlignment="Top" Width="50" DisplayMemberPath="Nm_Atr" ItemsSource="{Binding Source={StaticResource atributosNormaisViewSource}}" SelectedValuePath="Cd_AtributosNormais" SelectedValue="{Binding Cd_AtributosNormais, Source={StaticResource ataquesBasicosViewSource}}"/>
<ComboBox x:Name="btCmbAtkBaAtr3" HorizontalAlignment="Left" Margin="0,121,0,0" VerticalAlignment="Top" Width="50" DisplayMemberPath="Nm_Atr" ItemsSource="{Binding Source={StaticResource atributosNormaisViewSource}}" SelectedValuePath="Cd_AtributosNormais" SelectedValue="{Binding Cd_AtributosNormais, Source={StaticResource ataquesBasicosViewSource}}"/>
<ComboBox x:Name="btCmbAtkBaAtr4" HorizontalAlignment="Left" Margin="0,163,0,0" VerticalAlignment="Top" Width="50" DisplayMemberPath="Nm_Atr" ItemsSource="{Binding Source={StaticResource atributosNormaisViewSource}}" SelectedValuePath="Cd_AtributosNormais" SelectedValue="{Binding Cd_AtributosNormais, Source={StaticResource ataquesBasicosViewSource}}"/>

Tab1:

inserir a descrição da imagem aqui

Tab2:

inserir a descrição da imagem aqui

  • You speak of 4 Combobox but only posted the code of a.

  • All the others have the same code, what changes is their name. Thank you for fixing the code

  • If the code refers to Binding is the same in all, as the Binding mode by default is Mode=Twoway, by changing the value in one it is changed in the remaining.

  • And how could I solve this? Changing the mode of Binding?

  • I was wondering if the problem was not in the database, in table 1 in the case, because it will only create a new Row if I give the INSERT command, right?

  • Change the mode of Binding will not solve. As I have no idea what you intend it will not be easy to help. However, I think that, as each "Combobox" refers to different data, also each Binding has to refer to different things.

  • I will try to put images of the tables for better understanding and put the codes of the 4 cmb’s

  • You want to create 4 different records in Tab2 at the same time?

  • Exactly that

  • I guess you’ll have to have one then ataquesBasicosViewSource different for each combobox.

  • got it...I thought I could create 4 records in the same table automatically. Thanks for the help

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.