Answer the question
In order to leave comments, you need to log in
How to designate a ComboBox in the current context?
Hello everyone, I'm just getting started with wpf, maybe a very stupid question, but I've been scratching my head all day and can't figure out what the problem is.
I created a combobox in a DataTemplate, but when I try to somehow manipulate it from a .cs file, I get an error: The name "categoryComboBox" does not exist in the current context.
Here is the XAML code
<DataGrid x:Name="addDataGrid" HorizontalAlignment="Left" ItemsSource="{Binding}" Height="517" VerticalAlignment="Top" Width="975" Initialized="Window_Initialized_Add" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Категории">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox x:Name="categoryComboBox"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
//combobox
private MySqlDataAdapter categoryaddDataAdapter;
private void fillCategoryComboBox()
{
categoryaddDataAdapter = new MySqlDataAdapter
{
SelectCommand = new MySqlCommand()
{
Connection = programQuery,
CommandText = "SELECT * FROM category"
}
};
categoryaddDataAdapter.Fill(addDataSet, "category");
DataTable dtEmpName = addDataSet.Tables["category"];
categoryComboBox.ItemsSource = ((IListSource)dtEmpName).GetList();
categoryComboBox.SelectedValuePath = "id_category";
categoryComboBox.DisplayMemberPath = "name_category";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question