In this short post i will try to explain you how you can bind the comboBox with data source in wpf. Let us start with our example. i have put one comboBox in XAML and the XAML of the compboBox looks like
You can see that i have set the Grid.Column and Grid.Row property of the ComboBox so that in which column of the grid and in which row the comboBox is places and i also set the name of the combox which is cboItems. Now on my code behind what i did is to set the DataContext of the combox with the name of the table to which i want to bind the comboBox , here i have created local table at runtime and assign it to the comboBox. Next set the DisplayMemberPath which is used to dispaly the Text to the user and The SelectedValuePath which is used to save the key value which is used further if you need to do some processing on the selected combox Item.
Hope you will get some idea how you can bind the comboBox with the data from the database. if you have any question please feel free to ask me.
All and any comments / bugs / suggestions are welcomed!
1 comment:
can we bind a listview using WPF?
Post a Comment