c# - What is simplest way to bind this database content to WPF controls? -
i new wpf.
i have database table 2 columns: category, type. primary key combination (category, type). type subordinate category, meaning 1 category containing multiple type.
now, in wpf ui, have 2 combobox controls. first bind distinct category list in db table. have done binding control db view of distinct(category). second needs show type list belonging category selected in first control.
i did research have no idea how it. tried creating stored procedure select wanted type value list based on category given, don't know how pass selected category stored procedure in xaml. must use code rather xaml it? suggestion?
thanks lot
i create object hold categories contain each type possible category. like...
public class category { public observablecollection<string> types { get; set; } } then when initialize every category, can set types allowed in...
public class myclass { public observablecollection<category> categories { get; set; } public myclass() { initializecomponent(); observablecollection mytypes = new observablecollection(); mytypes.add("type1"); mytypes.add("type2"); mytypes.add("type3"); categories.add(new category() { types = mytypes }); //probably more elegant way this, hard based on information given this.datacontext = this; } } lastly can bind first combobox category list, , second types list of selected item of other combobox.
<combobox name="cbocategory" itemssource = "{binding categories}" /> <combobox itemssource = "{binding elementname=cbocategory, path=selecteditem.types}" />
Comments
Post a Comment