simsenVejle
Well-known member
- Joined
- Feb 14, 2021
- Messages
- 46
- Programming Experience
- Beginner
Hi,
I have problems getting the combobox to work.
I have a usercontrol with an listview and some controls. Everything works fine, when not using the combobox. Each time I click on one row in the ListView it should show in the controls (textboxes, labels and so on).
The list in the listview is of Category and here I have a key of ProjectId and a key of ProjectName. In the CategoryViewModel I have made an property SelectedCategory. No problems there at all
It works fine except I cann't update the combobox.
The combobox I take an ItemsSource of a list of Projects. Now I want to bind the ListView (LivCategories) with the ComboBox, so when selecting af Category, it shows me the project in the combobox for that specific Category. And I also want it to, if there isn't any projectId for a specific Category it should leave the combobox blank (or something to show here is no project)
I get the items by binding Projects_GetActive to the combobox (whitch succeded).
You can see in my code, I have made 2 textboxes, with ProjectId and ProjectName. Those two updates every time I select a new row in the Listview. So I have the right SelectedCategory. I do not know how to update the combobox.
If You miss some code please let me know - I don't have any secret part at all.
Best regards
Simsen
I have problems getting the combobox to work.
I have a usercontrol with an listview and some controls. Everything works fine, when not using the combobox. Each time I click on one row in the ListView it should show in the controls (textboxes, labels and so on).
The list in the listview is of Category and here I have a key of ProjectId and a key of ProjectName. In the CategoryViewModel I have made an property SelectedCategory. No problems there at all
It works fine except I cann't update the combobox.
The combobox I take an ItemsSource of a list of Projects. Now I want to bind the ListView (LivCategories) with the ComboBox, so when selecting af Category, it shows me the project in the combobox for that specific Category. And I also want it to, if there isn't any projectId for a specific Category it should leave the combobox blank (or something to show here is no project)
I get the items by binding Projects_GetActive to the combobox (whitch succeded).
You can see in my code, I have made 2 textboxes, with ProjectId and ProjectName. Those two updates every time I select a new row in the Listview. So I have the right SelectedCategory. I do not know how to update the combobox.
If You miss some code please let me know - I don't have any secret part at all.
Best regards
Simsen
My two Textboxes and the combobox that won't work:
<ComboBox x:Name="CbxProject" Text="Projekt" Grid.Row="5" Grid.Column="2" HorizontalContentAlignment="Left" VerticalContentAlignment="Center"
ItemsSource="{Binding Projects_GetActive}" DisplayMemberPath="ProjectName"
SelectedItem="{Binding ElementName=LivCategories, Path= SelectedValue.ProjectName, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" IsSynchronizedWithCurrentItem="True">
</ComboBox>
<TextBox x:Name="TxtProjectId" Margin="0 0 8 0" Text="{Binding ElementName=LivCategories, Path = SelectedValue.ProjectId, Mode = TwoWay}" Grid.Row="6" Grid.Column="1" Height="25" />
<TextBox x:Name="TxtProjectName" Margin="0 0 8 0" Text="{Binding ElementName=LivCategories, Path = SelectedValue.ProjectName, Mode = TwoWay}" Grid.Row="6" Grid.Column="2" Height="25" />
My ListView:
<ListView x:Name="LivCategories" ItemsSource="{Binding Categories_GetActive}" SelectedItem="{Binding SelectedCategory}" Grid.Row="0" Grid.Column="0">
<ListView.View>
<GridView>
<GridViewColumn Header="Id" Width="50" DisplayMemberBinding="{Binding CategoryId}"/>
<GridViewColumn Header="Navn" Width="250" DisplayMemberBinding="{Binding CategoryName}"/>
<GridViewColumn Header="Global" Width="50" DisplayMemberBinding="{Binding CategoryIsGlobal}"/>
<GridViewColumn Header="Project" Width="150" DisplayMemberBinding="{Binding ProjectName}"/>
<GridViewColumn Header="ProjectId" Width="0" DisplayMemberBinding="{Binding ProjectId}" />
</GridView>
</ListView.View>
</ListView>
SelectedCategory in CategoryViewModel:
private Category _selectedCategory;
public MyICommand DeleteCommand { get; set; }
public Category SelectedCategory
{
get
{
return _selectedCategory;
}
set
{
_selectedCategory = value;
OnPropertyChanged("SelectedCategory");
DeleteCommand.RaiseCanExecuteChanged();
}
}
INotifyPropertyChanged Members in CategoryViewModel:
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion