Forums - C# Corner

Forum guidelines
Varsha Vekariya

Varsha Vekariya

  • 1.7k
  • 76
  • 448

How to set autosuggest of DataGridComboBoxColumn WPF?

Apr 25 2019 1:25 AM
  1. <DataGridComboBoxColumn x:Name="list_itemname" Width="*" Header="Item Name" >  
  2.  <DataGridComboBoxColumn.ElementStyle>  
  3.  <Style TargetType="ComboBox">   
  4. <Setter Property="IsEditable" Value="True"/>  
  5.  <Setter Property="ItemsSource" Value="{Binding Path=itemlist }" />   
  6. </Style>   
  7. DataGridComboBoxColumn.ElementStyle>  
  8.  <DataGridComboBoxColumn.EditingElementStyle>  
  9.  <Style TargetType="ComboBox">   
  10. <Setter Property="IsEditable" Value="True"/>  
  11.  <Setter Property="ItemsSource" Value="{Binding Path=itemlist }" />  
  12.  </Style>   
  13. </DataGridComboBoxColumn.EditingElementStyle>   
  14. </DataGridComboBoxColumn>  
C# Code:
  1. public partial class page_addsale : Page  
  2.  {   
  3.  List itemlist = new List();  
  4.  ObservableCollection<Proxy> collection = new ObservableCollection<Proxy>();  
  5.  DataTable item_dt = new DataTable();   
  6. public page_addsale()   
  7. {   
  8.              InitializeComponent();   
  9.              con.Open(); OleDbDataAdapter ad = new OleDbDataAdapter("select id, item_name from item_list", con);  
  10.              ad.Fill(item_dt);  
  11.              con.Close();  
  12.  }   
  13. public class Proxy  
  14. {   
  15.    public string itemname { getset; }  
  16.    public string itemunit { getset; }  
  17. }   
  18. private void add_sale_Loaded(object sender, RoutedEventArgs e)  
  19.  {  
  20.              item_list.CanUserAddRows = true;  
  21.              item_list.AutoGenerateColumns = false;  
  22.                       string[] arr_item = item_dt.AsEnumerable().Select<System.Data.DataRow, String>(x => x.Field<String>("item_name")).ToArray();  
  23.              itemlist.AddRange(arr_item);  
  24.              list_itemname.ItemsSource = itemlist;  
  25.              item_list.ItemsSource = collection;  
  26.  }   
  27. }
 
 
after tab in unit column then DataGridComboBoxColumn selected item empty
 
 

Answers (1)