1

i m new in wpf. I can type text in the ComboBox but not display text. and How get value of DataGridComboBoxColumn WPF?

screenshot :

enter image description here

after tab in unit column then DataGridComboBoxColumn selected item empty

enter image description here

Xmal code Here :

<DataGrid  x:Name="item_list" AutoGenerateColumns="True" Height="410" CanUserResizeColumns="False" >
    <DataGrid.Columns>
        <DataGridComboBoxColumn x:Name="list_itemname" Width="*" Header="Item Name"  SelectedItemBinding="{Binding itemlist}">
            <DataGridComboBoxColumn.ElementStyle>
                <Style TargetType="ComboBox">
                    <Setter Property="IsEditable" Value="True"/>
                    <Setter Property="ItemsSource" Value="{Binding Path=itemlist }" />
                </Style>
            </DataGridComboBoxColumn.ElementStyle>
            <DataGridComboBoxColumn.EditingElementStyle>
                <Style TargetType="ComboBox">
                    <Setter Property="IsEditable" Value="True"/>
                    <Setter Property="ItemsSource" Value="{Binding Path=itemlist }"  />
                </Style>
            </DataGridComboBoxColumn.EditingElementStyle>
        </DataGridComboBoxColumn>
        <DataGridTextColumn x:Name="item_unit" Binding="{Binding itemunit}"   Width="*" Header="Unit"/>
    </DataGrid.Columns>     
</DataGrid>

c# Code Here :

public partial class page_addsale : Page
    {

        List<string> itemlist = new List<string>();
        ObservableCollection<Proxy> collection = new ObservableCollection<Proxy>();
        DataTable item_dt = new DataTable();

        public page_addsale()
        {
            InitializeComponent();

            con.Open();
            OleDbDataAdapter ad = new OleDbDataAdapter("select id, item_name from item_list", con);
            ad.Fill(item_dt);
            con.Close();     

        }       
        public class Proxy
        {
            public string itemname { get; set; }
            public string itemunit { get; set; }

        }
        private void add_sale_Loaded(object sender, RoutedEventArgs e)
        {
            tem_list.CanUserAddRows = true;
            item_list.AutoGenerateColumns = false;
            string[] arr_item = item_dt.AsEnumerable().Select<System.Data.DataRow, String>(x => x.Field<String>("item_name")).ToArray();
            itemlist.AddRange(arr_item);
            list_itemname.ItemsSource = itemlist;
            item_list.ItemsSource = collection;            
        }
    }   

how to solve this DataGridComboBoxColumn WPF

0 Answers0