What is easiest way to do this?

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

What is the easiest way to do this. I have a field in a Winform where I
want either and only a Y or an N (or perhaps a null).

One way is to use a combobox with a drop down list. Is there another? What
about a regular text field with a picture statement on it. Does the VS text
field support this? What are my options?
 
Woody,
In addition to a combobox w/drop down list, you can use a list box.

I would consider using a CheckBox, I would enable three state on the check
box for null.

You could also use a set of RadioButtons.

With CheckBoxes & RadioButtons you would need to 'translate' from boolean
values to Y or N. This might be easiest by deriving from CheckBox or
creating a UserControl with RadioButtons.

Hope this helps
Jay
 
Hello,

Woody Splawn said:
What is the easiest way to do this. I have a field in a
Winform where I want either and only a Y or an N
(or perhaps a null).

Why not use a CheckBox control (have a look at its 'ThreeState' property).
 
Thank you for responding
I would consider using a CheckBox, I would enable three state on the check
box for null.

Actually, this is what I am trying to avoid. If I use a 3-state check box it
forces the user to to consider what a null is etc., and in this case I think
it would be better to just give them a Y or N option.

With regard to doing this with a Drop down list, there are a couple of
things I don't understand. I have a Y/N (null) field scenario on a
Winform. I am using a combobox for this. I have DropDown Style set to drop
down list and in the Items collection I have Y and N. However, I have yet
to discover the combination of other properties that will allow me to
selecte either the Y or the N or to leave the field blank. I would like to
be able to leave the field blank and if left blank have it considered a
null. Is this possible? Right now, it will not allow me to enter anyting
into the field except a Y or an N.

Also I do not understand how to bind this field at design time. In the
databindings property I have three choices; selected Item, Selected Value
and Text. Which of these do I choose? I have tried all of them but they
all seem to have their quirks. If when the record first comes to the screen
there is a Y in it, if I choose a N instead and save the record, the N is
replaced by the Y. Don't understand why.

Am I using the right tool?
 
Woody,
If you have a Drop Down combo box and you want three options of Y, N or
blank. Add those three to the list.

ComboBox1.Items.Add("")
ComboBox1.Items.Add("Y")
ComboBox1.Items.Add("N")

Normally I wound bind to SelectedItem or SelectedValue depending on what is
contained in the list. (are they simple strings as above, or is there actual
objects in the list).

Remember if you are binding to a database field and that field is Boolean,
then you cannot bind to the string per se, I don't have an example, I
suspect will need to bind to an object that translates the string being
displayed and the boolean being stored.

Hope this helps
Jay
 
Back
Top