.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> WPF >> Post New QuestionBookmark and Share Subscribe to Forum

Combobox Binding in WPF

Posted By: Aamrapali Tamgadge     Posted Date: April 22, 2013    Points:5   Category :WPF
hello sir I have one datagrid inside that hav put one combobox as follws.and i have bind the data to it but the problem is that when i bind the data the selection is blank means my combobox is shown blank when user look at this but when i click it data is there.
but my requirement is that if there is already data is prsent in table then i have to bind that to combo.like we normally do using selected text and selected value..how to do this in this situation
also i wannt to find that comboboxcolumn.
Thanks in advance.
My code is


gridprincipal.ItemsSource = dt.DefaultView;

ds = objcbal.BAL_BindSearchGrid(cp);
DataTable dtexpert = ds.Tables[0];


DataGridTemplateColumn ComboColumn = new DataGridTemplateColumn();
ComboColumn.Header = "Expert Name"; ComboColumn.Width = 100;

FrameworkElementFactory ComboFactory = new FrameworkElementFactory(typeof(ComboBox));
ComboFactory.SetValue(ComboBox.ItemsSourceProperty, dtexpert.DefaultView);
ComboFactory.SetValue(ComboBox.DisplayMemberPathProperty, "Expert Name");
ComboFactory.SetValue(ComboBox.SelectedValuePathProperty, "Expert Code");
ComboFactory.SetValue(ComboBox.IsEditableProperty, true);
//ComboColumn.SetCurrentValue(ComboBox.SetIsSelected(ComboBox,0),true );

DataTemplate ComboCellTemplate = new DataTemplate();
ComboCellTemplate.VisualTree = ComboFactory;
ComboColumn.CellTemplate = ComboCellTemplate;

gridprincipal.Columns.Add(ComboColumn);

col = new DataGridTextColumn();
col.Header = "expertcode";
col.Binding = new Binding("expertcode");
gridprincipal.Columns.Add(col);

for (int j = 0; j < gridprincipal.Items.Count;j++ )
{

if (dt.Rows[j]["Expert Name"].ToString() != "")
{
string expname =dt.Rows[j]["ExpertName"].ToString();
DataGridCell cell = GetCell(j, 11);
//cell.Content = expname;



}


Responses
Author: Clintonzz             
Posted Date: February 07, 2014     Points: 20   

I happened to read something about the combobox data-binding, hope it helps:

http://www.kettic.com/winforms_ui/csharp_guide/multi_column_combobox_data_binding.shtml



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend