Can't set comboBox value that has valueMember / displayMember

Hello All,
I'm working on a project where I'm dynamically building a form according to a configuration schema. I'm pretty new at C# and got the following issue I can't get sorted out . 
Any help, advise would be great !!!
When building a ComboBox I can't set the value I want !!
Probably I'm missing something.
I've tried several methods but nothing does it ... below my code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ComboBoxSample
public partial class Form1 : Form
public Form1()
InitializeComponent();
CreateComboBox();
public void CreateComboBox(){
//Working variables
string valueMember = "idColumn";
string displayMember = "valueColumn";
//Create a panel and add to the form
TableLayoutPanel tlp = new TableLayoutPanel();
this.Controls.Add(tlp);
//Create the data source
DataTable dataTable = new DataTable();
dataTable.Columns.Add(valueMember, typeof(string));
dataTable.Columns.Add(displayMember, typeof(string));
dataTable.Rows.Add("A", "value A");
dataTable.Rows.Add("B", "value B");
dataTable.Rows.Add("C", "value C");
//Create a binding source
BindingSource bindingSource = new BindingSource(dataTable, null);
//Create a comboBox and bind the datasource
ComboBox comboBox = new ComboBox();
comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox.DataSource = bindingSource;
comboBox.ValueMember = valueMember;
comboBox.DisplayMember = displayMember;
Try and set the value
//No methode displays B --> combo stays on A
comboBox.SelectedValue = "B";
//comboBox.Text = "value B";
//comboBox.SelectedItem = comboBox.FindStringExact("value B");
//add the controles to the panel
tlp.Controls.Add(comboBox, 0, 0);

Hi Viorel_,
Thanks for the reply!!
The  setting the value in the form's Load event does work!
I agree for the form designer but it does not fit the need.
What I have is a "meta-data" driven logic where I define a screen that matches database fields:
Example : Screen new person has 5 fields : Gender (combobox) , first name (textbox) , last name (textbox) , type (combobox) ,birthday (datetime)
I have a Form derived class that takes this definition and builds each control at run time.
The definition also comes with potential default values (i.e. :type = client) so what I want to do is affect the value on the fly. This works fine with textbox or datetime. I'm trying to do the same for combobox.
Maybe I got this all wrong from a design point of view.

Similar Messages

  • I have three iPhones using the same iTunes account, can we set something so that we are not all getting everyones txt messages to all phones?

    I have three iPhones using the same iTunes account, can we set something so that all our txt messages are not appearing on all phones?

    Settings > Messages > Receive At...
    Any iPhone that lists the same email will receive the same texts. This has to be changed in order to stop receiving on all devices.

  • How can I set a value of column in SSIS by using Replace

    How can I set a value of a column in SSIS using a Replace in Derive columns. I have here NameCode and I need to Set = 1 Where NameCode like LIKE '____99____'
    eg. 1006993010... if 5th and 6th characters are 99
    Else 0
    Hope to hear from someone soon and I appreciate great help here.

    If NameCode column is integer then you have to cast it correctly to String.
    I am adding that to the expression provided by Rajen.
    SUBSTRING((DT_WSTR,20)ProductCode,5,2) == "99" ? 1 : 0
    -Vaibhav Chaudhari

  • How can I set the value to a session bean from backing bean

    Hi Experts,
    How can I set the value to a session bean from backing bean where I have created getter and setter
    methods for that variable.
    Basically I am using ADFUtils class where I am able to get the value from session bean
    using following expression
    String claimType =
    (String)ADFUtil.invokeEL("#{ClaimValueObj.getClaimType}");
    Thanks
    Gayaz

    Gayaz,
    Wrong Post !!
    Post in JDeveloper and ADF
    Thanks
    --Anil                                                                                                                                                                                                                               

  • Can I set the value of kernel paramaters less than default in Solaris 10?

    Can I set the value of kernel paramaters less than default in Solaris 10? If specified less than default values for kernel parameters in /etc/system, system is getting default values for such as SHMMAX, SEMMSL, SEMOPM. Is the default kernel parameter values the minimum values in Solaris 10?
    -Yong

    Yes, but not through /etc/system.
    /etc/system is the old way to do it. As a backward compatibility, it will allow lines there to increase parameters but not decrease them. This is on the theory that many memory defaults were significantly increased, and older /etc/system setups were trying to increase small defaults, not decrease large ones).
    Use prctl and set up a project.
    Darren

  • How can I set default values for Allocate Mode in AO config?

    Hi, How can I set default values for allocate mode in AO config. To be specific, in the attached vi, I need to set the Allocate Mode in AO Config to 'Use FIFO Memory (6)' if the value inside my case structure is false and to 'no change (0)' if the value inside the case strusture is true.
    Solved!
    Go to Solution.
    Attachments:
    generateWaveformFIFO.vi ‏15 KB

    Create two constants for the Allocate Mode input (right click > create > constant). Place one in the true case of the case structure, and place the other one in the false case. Wire them to the same tunnel (border of the case structure), then wire the tunnel to the Allocate Mode terminal of the AO Config. I don't have Traditional DAQ installed, but that should do it.
    Misha

  • How I can delete set of book that not use, it is creating wrongly?

    Dear Valued Consultant ,
    How I can delete set of book that not use, it is creating wrongly?
    Is there a way to delete Set of Book that not use, it is created wrongly?
    The Goal:
    This wrongly set of book it is appears always in any where that need select the Set of Book that may be cause select the wrongly one
    Thanks for alawys Helping

    Pl see if ML Doc 160623.1 (How to Delete a Set of Books from General Ledger?) helps.
    HTH
    Srini

  • How can I set the page that will open, when I open a new tab, to be the same as the homepage?

    How can I set the page that will open, when I open a new tab, to be the same as the homepage?
    An app changed it to some other search engine, before installing the app, I the tab that would open was the homepage I set.
    In my case it is Google, and I want my new tabs to open on Google like they did before the installation.
    thank you,
    Asaf Privman.

    You can middle-click or Ctrl left-click the Home button on the Navigation toolbar to open the Home page in a new tab.
    You can look at one of these extensions:
    * NewTabURL : https://addons.mozilla.org/firefox/addon/newtaburl/
    * New Tab Homepage : https://addons.mozilla.org/firefox/addon/new-tab-homepage/

  • How can I debug a sequence that has a subsequence is running in a separate thread?

    Hi,
    How can I debug a sequence that has a subsequence is running in a separate thread?
    I have to have a continues check for a  digital in signal to be able to terminate the sequence if a physical button is pushed.
    This is running in a separate thread, but this way I cannot debug the main sequence.
    Is there any workaround for this?
    Thanks,
    Andras

    This KB might help you:
    http://digital.ni.com/public.nsf/websearch/46D1E157756C37E686256CED0075E156?OpenDocument
    Let me know if this does not help.
    Allen P.
    NI

  • How can i copy a picture that has been installed with the flash player

    how can i copy a picture that has been installed using the flash player

    You can't. You can take a screen cap of it, but the container doesn't allow access to the individual images used in a SWF or FLV.

  • Can i set up tabs that automatically appear when i launch safari?

    can i set up tabs that automatically launch when i start safari?

    ... and, of course, if you have Lion and you leave the "resume" feature turned on, Safari will always start up in the state it was in when you quit it.
    charlie

  • Can you create a template that has a header and footer to forms?

    Can you create a template that has a header and footer to forms?

    Yes but how are they going to create the Landscape versions?
    The problem with doing it in Pages '09 as rotated content is that the Headers and Footers are not rotated and there is inherent clumsiness in the rotated content usually being too large for the page when viewed at 90°.
    Best to make it in two or more separate documents.
    Peter

  • HT4623 can i update my IPOD that has ios 4.2.1 to a least 6.0

    can i update my IPOD that has IOS 4.2.1 to a operation system that is at least 6.0 or higher

    If it's a second or third generation model, no.
    If it's a fourth, yes.
    If you don't know, append the last three characters of its serial number to http://www.everymac.com/ultimate-mac-lookup/?search_keywords= and load the page.
    (118814)

  • Upon launching Thunderbird, how can I set a password that will prevent viewing of my emails if someone uses my computer?

    Upon launching Thunderbird, how can I set a password that will prevent viewing of my emails if someone uses my computer?

    100% this addons can help you
    https://addons.mozilla.org/en-us/thunderbird/addon/master-password/
    look at my Thunderbird when I open it

  • Can you use an iPhone that has been locked in iCloud

    how can i unlock an iPhone that has ben locked in iCloud

    You won't be able to remove the existing iCloud account, restore or erase it without know the password.  If you ever update it or restore it you will not be able to activate it again and use it without knowing the correct ID and password.

Maybe you are looking for

  • How to lookup a value in a 2D array from an Excel file - Dasylab version 12 Pro

    Hi, I am new to this forum and am looking for some advice on a worksheet I'm trying to construct.  I have an Excel spreadsheet that is basically a 2D array, and I want to use Dasylab v12 Pro to be able to import a value from this array based on user

  • Phone not starting on it's own - solution :)

    A week or so ago, I was trying to find out why my new phone (not jailbroken or second-hand) would no longer boot up on it's own and had to be connected to the computer to get started. I was given some useful tips including how to do a complete restor

  • Use Ipod with Front Row

    Hey, I just got my new iMac core 2 duo and its awesome...I've been wondering if there is a way I can use Front Row with to access the music on my iPod. I have all my music on my ipod and don't want to sync it up with the computer(transfer all the fil

  • Incorrect Release code called which is not defined in a Release Strategy!

    Dear Gurus, I am facing a problem in Release strategy for a specific Purchase Requisition document type. My Release Strategy has two Release Codes for the Approval of a PR. When i create that document type of Purchase Requsition, Same Release Strateg

  • Blog Address not working in the RSS Widget

    I just updated to iWeb '09 and am trying to put my blog address into my website using the RSS Widget. However, it seems that the widget won't accept the address saying "The RSS feed source can't be reached" Am I missing something?