I have a Bit field (On/Off; True/False) that I would like to bind to a label and ComboBox, but I can't figure out how to have them display anything other than True or False. I'd like something like "Secure" "Unsecure" or "Male" "Female" but the text "Secure" corresponds to say, True and Unsecure False etc...

Any suggestions on how to successfully achieve this?

Recommended Answers

All 4 Replies

the simplest way is when you drag your table design from "data source window" to form design it create two check boxes for true or false constrains and it hold the relavant ans data in table database...there are many other ways too..

I'm only really interested in using labels and comboboxes. The check and radio buttons I can figure out, it's just the combobox and text label I can't.


here is a sample ..hope this will help you..

            cmd.Connection = con;
            cmd.CommandText = "insert into Table2 values('" + nameTextBox.Text + "','" + comboBox1.SelectedItem + "')";

the combo box is bound to a return type of Bit

table design


I still think you might be confused, but it's okay, it's probably me explaining it poorly.

I really have two questions. The goal is not to save data to the data source (well at least not necessarily), I know how to do that; the goal is to get a value that already exists in the data source (SQL in this case) in a bit field to be bound to a label that when bound doesn't say "True" or "False" but instead says "Male" or "Female" or in the case of a null bit value "Unspecified."

The second question is, for a combobox, is there a way to set a "SelectedValue" for each item in the combobox without binding the combobox to a datasource? Can the values be entered manually so that when the underlying data source is updated, and the user has selected "Male" from the combobox, the SQL statement doesn't pass the string "Male" or the integer value 1 to the server, but instead passes the boolean value "True."

I know there is a way to do this in code, I can achieve that without any issues, the question is can this be done with the IDE or is the best/only way to implement this by code alone?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.