Tuesday, February 25, 2014

ComboBox, ListBox and CheckListBox

** Image con not be displayed

-Goto property of fees Text box and change its name as TxtFees and set readonly  property as true, so that it becomes non editable and also set Text as zero(0).

- For every CheckBox and radio button provide a tag value, which should be the fees amount corresponding to course. Now for normal radio button use tag as zero.

Note – Tag property is also similar to text property, whereas, Tag is not visible to the end user, but both text and tag can be accessed in code by a programmer using text and tag properties.

- Now define a checked change event procedure for one CheckBox and bind this event procedure with all the other checkboxes.

- In the same way do it for radio button control also.

- Now write the following code under code view:
** Text con not be displayed

ComboBox, ListBox and CheckListBox: - we are using this control also for users to select from a list of available values.

ComboBox

it is allowing only single selection, but also allow the user to enter a new value in Run time.

ListBox

It is by default allows single selection but can be customized into multi selection.

CheckListBox

Is always by-default allows multi selection.

Adding values to the control: - 

If we want to add values to the control, we have various mechanisms:
  • Under the properties of the control  select items property and click on the button beside it, which opens a window and under it enter your required values.
  • Using Items.Add method a value can be added to the control at any time.
    < Control >. Items.Add ( object values )

  •       Using the Items.AddRange method of thee control, an array of values can be at a time bound to them.
    Eg: 
    < control > . Items.AddRange ( object [] values )
  • .      Using the data source property of the control, a data table can be bounded to the control, but again using display member property, we need to specify which column of the table has to be display.

    Eg:
    < Control > .DataSource = < data table >
    <control > DisplayMember = < Col name >

Multiple selection under ListBox

As discussed earlier a ListBox control allows only single selection, If we want to go for multi selection, we need to set the selection mode property of the control either as MultiSimple (only mouse click) or MultiExtended (ctrl + Mouse click).
Identify selected values from the controls: -

ComboBox:
- Text
String
- SelectedItem
object
SelectedIndex
int
ListBox
- SelectedItem
object
- SelectedItems
object []
-SelectedIndex
int
- SelectedIndices
int []

CheckListBox
- CheckedItems
object []
- CheckedIndices
int []

No comments: