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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. ComboBox index Databind

ComboBox index Databind

Scheduled Pinned Locked Moved C#
database
2 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.
  • K Offline
    K Offline
    Kaikus
    wrote on last edited by
    #1

    Hi! I have a dataset colum wich values ara simple integers. I want to create a ComboBox with some string values, and databind the dataset as an INDEX to them. So, dataset has 1,2,3,4 my Combobox has "myString1", "myString2" (I can popolate manually or progrmatically, but theese values are NOT provided by the dataset) I want to databind my dataset to my combobox so that when dataset value is 2, the combobox show "myString2". I think it should be easy... but i'm not too used to combobox neither databind Thanks!

    T 1 Reply Last reply
    0
    • K Kaikus

      Hi! I have a dataset colum wich values ara simple integers. I want to create a ComboBox with some string values, and databind the dataset as an INDEX to them. So, dataset has 1,2,3,4 my Combobox has "myString1", "myString2" (I can popolate manually or progrmatically, but theese values are NOT provided by the dataset) I want to databind my dataset to my combobox so that when dataset value is 2, the combobox show "myString2". I think it should be easy... but i'm not too used to combobox neither databind Thanks!

      T Offline
      T Offline
      The Man from U N C L E
      wrote on last edited by
      #2

      If you set the datasource for a combobox then the datasource must contain both the ValueMember and the DisplayMember otherwise it will not work. in order to databind the ValueMember must point to a corresponding value in the datasource eg. Your datasource for the combobox would be a datatable such as: ID VALUE ============= 1 myString1 2 myString2 Your dataset would have a column in the table (MyTable) containing the idStrings value for example.

      MyCombo.DataSource = source;
      MyCombo.ValueMember = "ID";
      MyCombo.DisplayMember = "VALUE"

      MyCombo.DataBindings.Add("SelectedValue", MyData, "idStrings")

      If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

      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