• Как вывести текст в свернутый combobox?

    @noire_night Автор вопроса
    Получилось сделать вот так:
    <DataGridComboBoxColumn x:Name="categoryComboBox" Header="Категории" ItemsSource="{Binding category}">
                                    <DataGridComboBoxColumn.EditingElementStyle>
                                        <Style TargetType="{x:Type ComboBox}">
                                            <EventSetter Event="Loaded" Handler="CategoryComboBoxLoaded" />
                                        </Style>
                                    </DataGridComboBoxColumn.EditingElementStyle>
                                </DataGridComboBoxColumn>


    private void CategoryComboBoxLoaded(object sender, EventArgs e)
            {
                var categoryComboBox = sender as ComboBox;
    
                addDataAdapter = new MySqlDataAdapter
                {
                    SelectCommand = new MySqlCommand()
                    {
                        Connection = programQuery,
                        CommandText = "SELECT * FROM category"
                    }
                };
    
                DataTable dtEmpName = addDataSet.Tables["category"];
                categoryComboBox.ItemsSource = ((IListSource)dtEmpName).GetList();
                categoryComboBox.SelectedValuePath = "id_category";
                categoryComboBox.DisplayMemberPath = "name_category";
    
                //var selectedItem = this.addDataGrid.CurrentItem;
    
                categoryComboBox.SelectedIndex = 0;
    
            }
    Ответ написан
    Комментировать
  • Как обозначить ComboBox в текущем контексте?

    @noire_night Автор вопроса
    Вопрос решен
    <DataGridComboBoxColumn x:Name="testComboBox" ItemsSource="{Binding category}" Header="Категории" DisplayMemberPath="id_category" SelectedValuePath="name_category"/>

    private void FilltestComboBox()
            {
                addDataAdapter = new MySqlDataAdapter
                {
                    SelectCommand = new MySqlCommand()
                    {
                        Connection = programQuery,
                        CommandText = "SELECT * FROM category"
                    }
                };
    
                addDataAdapter.Fill(addDataSet, "category");
                DataTable dtEmpName = addDataSet.Tables["category"];
                testComboBox.ItemsSource = ((IListSource)dtEmpName).GetList();
                testComboBox.SelectedValuePath = "id_category";
                testComboBox.DisplayMemberPath = "name_category";
    
            }
    Ответ написан
    Комментировать