Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. c# combo box binding

c# combo box binding

Scheduled Pinned Locked Moved C#
wpfcsharpwcfdesigntutorial
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pubudini34
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • P Pubudini34

      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

      C Offline
      C Offline
      Cracked Down
      wrote on last edited by
      #2

      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 :)

      P 1 Reply Last reply
      0
      • C Cracked Down

        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 :)

        P Offline
        P Offline
        Pubudini34
        wrote on last edited by
        #3

        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.cs

        using 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

        C 1 Reply Last reply
        0
        • P Pubudini34

          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.cs

          using 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

          C Offline
          C Offline
          Cracked Down
          wrote on last edited by
          #4

          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

          P 1 Reply Last reply
          0
          • C Cracked Down

            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

            P Offline
            P Offline
            Pubudini34
            wrote on last edited by
            #5

            It worked... :) Thankx alotttt.It helped me alot.

            C 1 Reply Last reply
            0
            • P Pubudini34

              It worked... :) Thankx alotttt.It helped me alot.

              C Offline
              C Offline
              Cracked Down
              wrote on last edited by
              #6

              welcome..please mark this as resolved.

              P 2 Replies Last reply
              0
              • C Cracked Down

                welcome..please mark this as resolved.

                P Offline
                P Offline
                Pubudini34
                wrote on last edited by
                #7

                :thumbsup: AS i am new to this i dont know how to mark this as resolved.Can you tel?Your answer really helped me

                1 Reply Last reply
                0
                • C Cracked Down

                  welcome..please mark this as resolved.

                  P Offline
                  P Offline
                  Pubudini34
                  wrote on last edited by
                  #8

                  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 :

                  C 1 Reply Last reply
                  0
                  • P Pubudini34

                    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 :

                    C Offline
                    C Offline
                    Cracked Down
                    wrote on last edited by
                    #9

                    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 :)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups