c# combo box binding
-
Hey, I have been struggling to bind a combo box and a text box.Finally it happened, but unfortunately the text that i have selected in the combo appears with additional wordings. Ex : I select the word " FISH" from the combo , so i expect that word to appear in text box that i have bind.But instead of that System.Windows.Controls.ComboBoxItem: fish appears.How to solve this.Please tel me how to correct this in design view or by xaml.Thank you
-
Hey, I have been struggling to bind a combo box and a text box.Finally it happened, but unfortunately the text that i have selected in the combo appears with additional wordings. Ex : I select the word " FISH" from the combo , so i expect that word to appear in text box that i have bind.But instead of that System.Windows.Controls.ComboBoxItem: fish appears.How to solve this.Please tel me how to correct this in design view or by xaml.Thank you
you need to set the path to Selected value in the binding. refer below code
Text="{Binding ElementName=comboBox1, Path=SelectedValue}"/>
in the code expose property as
public List CMBItems
{
get
{
return new List { "a","b","c","d"};
}
}Hope this will help! Happy Coding :)
-
you need to set the path to Selected value in the binding. refer below code
Text="{Binding ElementName=comboBox1, Path=SelectedValue}"/>
in the code expose property as
public List CMBItems
{
get
{
return new List { "a","b","c","d"};
}
}Hope this will help! Happy Coding :)
Thankx alot.I treid as you have said.But still the same mistake appears .I will paste my code lines
class.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;namespace WpfApplication16
{
public class Class1
{
string lname = "Di";
public string MyProperty
{
get { return lname; }
set
{//comboBox1.SelectedItem.ToString();
lname = Convert.ToString(value);Debug.WriteLine("----------------------------->>>" + lname);
}
}}
}======================================================
MainWindow.xaml=======================================================
MainWindow.xaml.csusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;namespace WpfApplication16
{
////// Interaction logic for MainWindow.xaml
///public part
-
Thankx alot.I treid as you have said.But still the same mistake appears .I will paste my code lines
class.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;namespace WpfApplication16
{
public class Class1
{
string lname = "Di";
public string MyProperty
{
get { return lname; }
set
{//comboBox1.SelectedItem.ToString();
lname = Convert.ToString(value);Debug.WriteLine("----------------------------->>>" + lname);
}
}}
}======================================================
MainWindow.xaml=======================================================
MainWindow.xaml.csusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;namespace WpfApplication16
{
////// Interaction logic for MainWindow.xaml
///public part
Code file:
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace WpfApplication1
{
/// /// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
}public List CMBItems { get { return new List { "a","b","c","d"}; } } }
}
xaml
-
Code file:
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace WpfApplication1
{
/// /// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
}public List CMBItems { get { return new List { "a","b","c","d"}; } } }
}
xaml
It worked... :) Thankx alotttt.It helped me alot.
-
It worked... :) Thankx alotttt.It helped me alot.
welcome..please mark this as resolved.
-
welcome..please mark this as resolved.
:thumbsup: AS i am new to this i dont know how to mark this as resolved.Can you tel?Your answer really helped me
-
welcome..please mark this as resolved.
The previous problem was solved... ======================================== here comes a new one public DataView MyProperty { get { return theTable.DefaultView; } set { theTable = value; } } Basically what i want to do now is - 1.connect to a data base 2.Get the data and set the data set with MyProperty 3.Bind the Property with ComboBox Final Result -> ComboBox should show all the data retreved from the data base xaml code :
-
The previous problem was solved... ======================================== here comes a new one public DataView MyProperty { get { return theTable.DefaultView; } set { theTable = value; } } Basically what i want to do now is - 1.connect to a data base 2.Get the data and set the data set with MyProperty 3.Bind the Property with ComboBox Final Result -> ComboBox should show all the data retreved from the data base xaml code :
In the main question that you posted look at the bottom you will find the resolved option Before posting on CP first check for the solution online (google).. if you dont find it there then CP is always there........ Happy Coding :)