0% found this document useful (0 votes)
6 views17 pages

ComboBox Properties

The document provides a comprehensive overview of the properties, events, and methods associated with the ComboBox control in Windows Forms, including examples of their usage. Key properties include Items, SelectedIndex, and DropDownStyle, while events such as SelectedIndexChanged and DropDown are highlighted. Additionally, methods like AddRange, FindString, and BeginUpdate offer further customization and interaction capabilities for developers working with ComboBox controls.

Uploaded by

Ahmed Al-nasheri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views17 pages

ComboBox Properties

The document provides a comprehensive overview of the properties, events, and methods associated with the ComboBox control in Windows Forms, including examples of their usage. Key properties include Items, SelectedIndex, and DropDownStyle, while events such as SelectedIndexChanged and DropDown are highlighted. Additionally, methods like AddRange, FindString, and BeginUpdate offer further customization and interaction capabilities for developers working with ComboBox controls.

Uploaded by

Ahmed Al-nasheri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

ComboBox : Properties, Events, and Methods Examples

Here are some properties, events, and methods of the ComboBox control in Windows Forms, along with
examples of their usage:

Properties:

1. Items: Gets or sets the collection of items in the ComboBox.

comboBox1.Items.Add("Item 1"); // Add an item to the ComboBox

comboBox1.Items.Clear(); // Clear all items from the ComboBox

2. SelectedIndex: Gets or sets the zero-based index of the currently selected item.

int selectedIndex = comboBox1.SelectedIndex; // Get the index of the selected item

comboBox1.SelectedIndex = 0; // Set the selected item to the first item

3. SelectedValue: Gets or sets the value of the currently selected item.

string selectedValue = comboBox1.SelectedValue.ToString(); // Get the value of the selected

item

comboBox1.SelectedValue = "Value1"; // Set the selected item based on its value

4. DropDownStyle: Gets or sets a value that specifies how the ComboBox control appears when
the drop-down list is displayed.

comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; // Set the ComboBox to a drop-


down list style

Events:

1. SelectedIndexChanged: Occurs when the selected index of the ComboBox has changed.

comboBox1.SelectedIndexChanged += ComboBox1_SelectedIndexChanged;

private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)

// Handle the selected index changed event

2. DropDown: Occurs when the drop-down portion of the ComboBox is shown.

comboBox1.DropDown += ComboBox1_DropDown;

Dr. Ahmed Alnasheri 1/17


private void ComboBox1_DropDown(object sender, EventArgs e)

// Handle the drop-down event

Methods:

1. AddRange: Adds an array of items to the ComboBox.

string[] itemsArray = { "Item 1", "Item 2", "Item 3" };

comboBox1.Items.AddRange(itemsArray); // Add multiple items to the ComboBox

2. FindString: Searches for the first item in the ComboBox that starts with the specified string.

int index = comboBox1.FindString("Item 2"); // Find the index of the item starting with "Item 2"

3. BeginUpdate and EndUpdate: Temporarily suspends the painting of the ComboBox until
the EndUpdate method is called.

comboBox1.BeginUpdate();

// Perform multiple operations on the ComboBox

comboBox1.EndUpdate();

These are some of the properties, events, and methods available in the ComboBox control that allow
you to customize and interact with the control. You can explore their usage and adapt them to suit your
specific requirements in your Windows Forms application.

Here are some additional details about properties, events, and methods of the ComboBox control in
Windows Forms:

Properties:

1. Text: Gets or sets the text associated with the currently selected item or the text entered by the
user.

string selectedText = comboBox1.Text; // Get the text of the selected item or user-entered text

comboBox1.Text = "New Text"; // Set the text of the ComboBox

2. DropDownWidth: Gets or sets the width, in pixels, of the drop-down portion of the ComboBox.

comboBox1.DropDownWidth = 200; // Set the width of the drop-down portion to 200 pixels

3. MaxDropDownItems: Gets or sets the maximum number of items to be shown in the drop-down
portion of the ComboBox.

comboBox1.MaxDropDownItems = 5; // Set the maximum number of items in the drop-down

portion to 5

Dr. Ahmed Alnasheri 2/17


Events:

1. DropDownClosed: Occurs when the drop-down portion of the ComboBox is closed.

comboBox1.DropDownClosed += ComboBox1_DropDownClosed;

private void ComboBox1_DropDownClosed(object sender, EventArgs e)

// Handle the drop-down closed event

2. TextChanged: Occurs when the Text property of the ComboBox has changed.

comboBox1.TextChanged += ComboBox1_TextChanged;

private void ComboBox1_TextChanged(object sender, EventArgs e)

// Handle the text changed event

Methods:

1. FindStringExact: Searches for the first item in the ComboBox that exactly matches the specified
string.

int index = comboBox1.FindStringExact("Item 2"); // Find the index of the item that exactly
matches "Item 2"

2. Select: Selects the text within the ComboBox.

comboBox1.Select(0, comboBox1.Text.Length); // Select the entire text within the ComboBox

3. DroppedDown: Gets or sets a value indicating whether the drop-down portion of


the ComboBox is currently displayed.

bool isDroppedDown = comboBox1.DroppedDown; // Check if the drop-down portion of the

ComboBox is displayed

comboBox1.DroppedDown = true; // Display the drop-down portion of the ComboBox

4. GetItemText: Retrieves the text representation of the specified item in the ComboBox.

string itemText = comboBox1.GetItemText(comboBox1.SelectedItem); // Get the text of the

selected item

Dr. Ahmed Alnasheri 3/17


These additional properties, events, and methods provide further customization and functionality to
the ComboBox control in Windows Forms. You can explore their usage and leverage them to enhance
the behavior and interaction of the ComboBox in your application.

Here are some more details about properties, events, and methods of the ComboBox control in
Windows Forms:

Properties:

1. DropDownHeight: Gets or sets the height, in pixels, of the drop-down portion of the ComboBox.

comboBox1.DropDownHeight = 150; // Set the height of the drop-down portion to 150 pixels

2. AutoCompleteMode and AutoCompleteSource: Enables automatic completion of text as the


user types in the ComboBox based on a specified mode and source.

comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; // Set the auto-


complete mode

comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; // Set the auto-complete


source

3. DropDownAnchor: Gets or sets a value indicating the location of the drop-down portion relative
to the ComboBox.

comboBox1.DropDownAnchor = ComboBoxRightToLeft.Right; // Set the drop-down anchor to


appear on the right side

Events:

1. KeyPress: Occurs when a key is pressed while the ComboBox has focus.

comboBox1.KeyPress += ComboBox1_KeyPress;

private void ComboBox1_KeyPress(object sender, KeyPressEventArgs e)

// Handle the key press event

2. Validating and Validated: Occur when the ComboBox is validating its contents and after the
validation is complete.

comboBox1.Validating += ComboBox1_Validating;

comboBox1.Validated += ComboBox1_Validated;

private void ComboBox1_Validating(object sender, CancelEventArgs e)

// Handle the validating event

Dr. Ahmed Alnasheri 4/17


}

private void ComboBox1_Validated(object sender, EventArgs e)

// Handle the validated event

Methods:

1. BeginInvoke: Executes a delegate asynchronously on the thread that the ComboBox control's
underlying handle was created on.

comboBox1.BeginInvoke((MethodInvoker)delegate

// Perform an action on the ComboBox asynchronously

});

2. GetItemHeight: Retrieves the height, in pixels, of an item in the ComboBox.

int itemHeight = comboBox1.GetItemHeight(0); // Get the height of the first item in the
ComboBox

3. IsHandleCreated: Gets a value indicating whether the control has a handle associated with it.

bool isHandleCreated = comboBox1.IsHandleCreated; // Check if the ComboBox has a handle


associated with it

4. Refresh: Forces the ComboBox control to invalidate its client area and immediately redraw itself
and any child controls.

comboBox1.Refresh(); // Refresh the ComboBox control and its child controls

These additional properties, events, and methods provide even more flexibility and control over the
behavior and appearance of the ComboBox control in your Windows Forms application. You can explore
their usage and leverage them to meet your specific requirements.

Here are some more details about properties, events, and methods of the ComboBox control in
Windows Forms:

Properties:

1. IntegralHeight: Gets or sets a value indicating whether the control automatically adjusts its
height to display an integral number of items.

comboBox1.IntegralHeight = false; // Allow non-integral height for the ComboBox

2. MaxLength: Gets or sets the maximum number of characters a user can enter into
the ComboBox.

Dr. Ahmed Alnasheri 5/17


comboBox1.MaxLength = 50; // Set the maximum character limit to 50

3. Sorted: Gets or sets a value indicating whether the items in the ComboBox are sorted
alphabetically.

comboBox1.Sorted = true; // Sort the items in the ComboBox alphabetically

Events:

1. MouseEnter and MouseLeave: Occur when the mouse pointer enters or leaves
the ComboBox control.

comboBox1.MouseEnter += ComboBox1_MouseEnter;

comboBox1.MouseLeave += ComboBox1_MouseLeave;

private void ComboBox1_MouseEnter(object sender, EventArgs e)

// Handle the mouse enter event

private void ComboBox1_MouseLeave(object sender, EventArgs e)

// Handle the mouse leave event

2. KeyDown and KeyUp: Occur when a key is pressed or released while the ComboBox has focus.

comboBox1.KeyDown += ComboBox1_KeyDown;

comboBox1.KeyUp += ComboBox1_KeyUp;

private void ComboBox1_KeyDown(object sender, KeyEventArgs e)

// Handle the key down event

private void ComboBox1_KeyUp(object sender, KeyEventArgs e)

// Handle the key up event

Dr. Ahmed Alnasheri 6/17


Methods:

1. SelectAll: Selects all the text in the editable portion of the ComboBox.

comboBox1.SelectAll(); // Select all text in the ComboBox

2. GetItemHeight: Retrieves the height, in pixels, of an item in the ComboBox.

int itemHeight = comboBox1.GetItemHeight(0); // Get the height of the first item in the

ComboBox

3. Hide: Hides the ComboBox control from the user.

comboBox1.Hide(); // Hide the ComboBox control

4. Show: Displays the ComboBox control to the user.

comboBox1.Show(); // Show the ComboBox control

These additional properties, events, and methods provide further control and customization options for
the ComboBox control in Windows Forms. You can explore their usage and adapt them to suit your
specific requirements in your application.

Here are some more details about properties, events, and methods of the ComboBox control in
Windows Forms:

Properties:

1. DropDownStyle: Gets or sets a value indicating whether the ComboBox is a drop-down list or a
drop-down combo box.

comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; // Set the ComboBox as a drop-

down list

2. SelectedIndex: Gets or sets the zero-based index of the currently selected item in
the ComboBox.

int selectedIndex = comboBox1.SelectedIndex; // Get the index of the selected item

comboBox1.SelectedIndex = 2; // Set the selected item to index 2

3. Items: Gets a collection of items contained within the ComboBox.

comboBox1.Items.Add("Item 1"); // Add an item to the ComboBox

comboBox1.Items.Remove("Item 2"); // Remove an item from the ComboBox

Events:

1. SelectedIndexChanged: Occurs when the SelectedIndex property has changed.

comboBox1.SelectedIndexChanged += ComboBox1_SelectedIndexChanged;

Dr. Ahmed Alnasheri 7/17


private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)

// Handle the selected index changed event

2. DropDown: Occurs when the drop-down portion of the ComboBox is shown.

comboBox1.DropDown += ComboBox1_DropDown;

private void ComboBox1_DropDown(object sender, EventArgs e)

// Handle the drop-down event

Methods:

1. BeginUpdate and EndUpdate: Temporarily suspends the drawing of the ComboBox control until
the EndUpdate method is called.

comboBox1.BeginUpdate(); // Suspend updates to the ComboBox

// Perform multiple operations on the ComboBox

comboBox1.EndUpdate(); // Resume updates and refresh the ComboBox

2. FindString: Searches for the first item in the ComboBox that contains the specified string.

int index = comboBox1.FindString("Item 3"); // Find the index of the item that contains "Item 3"

3. ResetText: Resets the Text property to its default value.

comboBox1.ResetText(); // Reset the text of the ComboBox to its default value

These additional properties, events, and methods provide more functionality and control over
the ComboBox control in Windows Forms. You can explore their usage and adapt them to meet your
specific needs in your application.

Here are some additional details about the ComboBox control in Windows Forms:

Properties:

1. Text: Gets or sets the text associated with the ComboBox.

string comboBoxText = comboBox1.Text; // Get the current text of the ComboBox

comboBox1.Text = "New Text"; // Set the text of the ComboBox

Dr. Ahmed Alnasheri 8/17


2. DropDownWidth: Gets or sets the width of the drop-down portion of the ComboBox.

comboBox1.DropDownWidth = 200; // Set the width of the drop-down portion to 200 pixels

3. FlatStyle: Gets or sets the flat style appearance of the ComboBox.

comboBox1.FlatStyle = FlatStyle.Flat; // Set the flat style appearance

Events:

1. DropDownClosed: Occurs when the drop-down portion of the ComboBox is closed.

comboBox1.DropDownClosed += ComboBox1_DropDownClosed;

private void ComboBox1_DropDownClosed(object sender, EventArgs e)

// Handle the drop-down closed event

2. Validating and Validated: Occur when the ComboBox is validating its contents and after the
validation is complete.

comboBox1.Validating += ComboBox1_Validating;

comboBox1.Validated += ComboBox1_Validated;

private void ComboBox1_Validating(object sender, CancelEventArgs e)

// Handle the validating event

private void ComboBox1_Validated(object sender, EventArgs e)

// Handle the validated event

Methods:

1. Copy: Copies the selected text in the ComboBox to the clipboard.

comboBox1.Copy(); // Copy the selected text in the ComboBox to the clipboard

2. DeselectAll: Deselects any selected text in the editable portion of the ComboBox.

comboBox1.DeselectAll(); // Deselect any selected text in the ComboBox

3. GetService: Retrieves the service object of the specified type, if it is available.

Dr. Ahmed Alnasheri 9/17


var service = comboBox1.GetService(typeof(MyService)); // Get the service object of type

MyService

These additional properties, events, and methods provide even more functionality and customization
options for the ComboBox control in Windows Forms. You can explore their usage and adapt them to
meet your specific application requirements.

Here are some additional details about the ComboBox control in Windows Forms:

Properties:

1. BackColor: Gets or sets the background color of the ComboBox.

comboBox1.BackColor = Color.LightBlue; // Set the background color of the ComboBox to light

blue

2. ForeColor: Gets or sets the foreground color of the ComboBox.

comboBox1.ForeColor = Color.DarkRed; // Set the foreground color of the ComboBox to dark

red

3. DropDownHeight: Gets or sets the height, in pixels, of the drop-down portion of the ComboBox.

comboBox1.DropDownHeight = 200; // Set the height of the drop-down portion to 200 pixels

Events:

1. TextChanged: Occurs when the Text property of the ComboBox has changed.

comboBox1.TextChanged += ComboBox1_TextChanged;

private void ComboBox1_TextChanged(object sender, EventArgs e)

// Handle the text changed event

2. MouseClick: Occurs when the ComboBox control is clicked with the mouse.

comboBox1.MouseClick += ComboBox1_MouseClick;

private void ComboBox1_MouseClick(object sender, MouseEventArgs e)

// Handle the mouse click event

Dr. Ahmed Alnasheri 10/17


Methods:

1. Clear: Removes all items from the ComboBox.

comboBox1.Clear(); // Remove all items from the ComboBox

2. GetSelected: Retrieves the value associated with the currently selected item in the ComboBox.

var selectedValue = comboBox1.SelectedValue; // Get the value associated with the currently

selected item

3. FindStringExact: Searches for the first item in the ComboBox that exactly matches the specified
string.

int index = comboBox1.FindStringExact("Item 3"); // Find the index of the item that exactly

matches "Item 3"

These additional properties, events, and methods provide further control and customization options for
the ComboBox control in Windows Forms. You can explore their usage and adapt them to meet your
specific application requirements.

Here are some additional details about the ComboBox control in Windows Forms:

Properties:

1. AutoCompleteMode: Gets or sets a value indicating the automatic completion behavior of


the ComboBox.

comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest; // Set the auto-complete mode

to suggest

2. AutoCompleteSource: Gets or sets the source used to automatically


complete ComboBox entries.

comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; // Set the auto-complete

source to the list items

3. DropDownAnchor: Gets or sets a value indicating where the ComboBox is anchored when its
drop-down is displayed.

comboBox1.DropDownAnchor = ComboBoxDropDownAnchor.Right; // Set the drop-down

anchor to the right

Events:

1. Format: Occurs when the ComboBox is bound to a data source and a data-bound value needs to
be formatted.

comboBox1.Format += ComboBox1_Format;

Dr. Ahmed Alnasheri 11/17


private void ComboBox1_Format(object sender, ListControlConvertEventArgs e)

// Handle the format event

2. MeasureItem: Occurs when an owner-drawn ComboBox needs to measure an item.

comboBox1.MeasureItem += ComboBox1_MeasureItem;

private void ComboBox1_MeasureItem(object sender, MeasureItemEventArgs e)

// Handle the measure item event

Methods:

1. GetItemText: Retrieves the text of the specified item in the ComboBox.

string itemText = comboBox1.GetItemText(comboBox1.SelectedItem); // Get the text of the


selected item

2. GetSelectedIndex: Retrieves the index of the first item in the ComboBox that matches the
specified string.

int index = comboBox1.GetSelectedIndex("Item 3"); // Get the index of the first item that
matches "Item 3"

3. Refresh: Forces the ComboBox to repaint its surface and display any changes.

comboBox1.Refresh(); // Refresh the ComboBox to display any changes

These additional properties, events, and methods provide even more functionality and control over
the ComboBox control in Windows Forms. You can explore their usage and adapt them to meet your
specific application requirements.

Here are some additional details about the ComboBox control in Windows Forms:

Properties:

1. MaxDropDownItems: Gets or sets the maximum number of items to be shown in the drop-down
portion of the ComboBox.

comboBox1.MaxDropDownItems = 10; // Set the maximum number of items to be shown to 10

Dr. Ahmed Alnasheri 12/17


2. IntegralHeight: Gets or sets a value indicating whether the ComboBox should resize to avoid
showing partial items.

comboBox1.IntegralHeight = false; // Allow the ComboBox to display partial items

3. SelectedText: Gets or sets the selected text in the editable portion of the ComboBox.

string selectedText = comboBox1.SelectedText; // Get the selected text in the ComboBox

comboBox1.SelectedText = "New Text"; // Set the selected text in the ComboBox

Events:

1. DrawItem: Occurs when the ComboBox needs to paint an item.

comboBox1.DrawItem += ComboBox1_DrawItem;

private void ComboBox1_DrawItem(object sender, DrawItemEventArgs e)

// Handle the draw item event

2. DropDownStyleChanged: Occurs when the DropDownStyle property has changed.

comboBox1.DropDownStyleChanged += ComboBox1_DropDownStyleChanged;

private void ComboBox1_DropDownStyleChanged(object sender, EventArgs e)

// Handle the drop-down style changed event

Methods:

1. Select: Selects a range of text in the editable portion of the ComboBox.

comboBox1.Select(0, 5); // Select the first 5 characters in the ComboBox

2. SelectAll: Selects all the text in the editable portion of the ComboBox.

comboBox1.SelectAll(); // Select all the text in the ComboBox

3. Update: Forces the ComboBox to update its display.

comboBox1.Update(); // Update the display of the ComboBox

These additional properties, events, and methods provide additional functionality and control over
the ComboBox control in Windows Forms. You can explore their usage and adapt them to meet your
specific application requirements.

Dr. Ahmed Alnasheri 13/17


Here are some additional details about the ComboBox control in Windows Forms:

Properties:

1. DropDownStyle: Gets or sets the style of the drop-down portion of the ComboBox.

comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; // Set the drop-down style to a

drop-down list

2. Items: Gets the collection of items contained in the ComboBox.

comboBox1.Items.Add("Item 1"); // Add an item to the ComboBox

comboBox1.Items.Remove("Item 1"); // Remove an item from the ComboBox

3. SelectedIndex: Gets or sets the index of the currently selected item in the ComboBox.

int selectedIndex = comboBox1.SelectedIndex; // Get the index of the currently selected item

comboBox1.SelectedIndex = 0; // Set the currently selected item by index

Events:

1. SelectedIndexChanged: Occurs when the SelectedIndex property has changed.

comboBox1.SelectedIndexChanged += ComboBox1_SelectedIndexChanged;

private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)

// Handle the selected index changed event

2. DropDown: Occurs when the drop-down portion of the ComboBox is shown.

comboBox1.DropDown += ComboBox1_DropDown;

private void ComboBox1_DropDown(object sender, EventArgs e)

// Handle the drop-down event

Methods:

1. BeginUpdate: Prevents the ComboBox from updating until the EndUpdate method is called.

comboBox1.BeginUpdate(); // Begin updating the ComboBox

// Update the ComboBox items

comboBox1.EndUpdate(); // End updating the ComboBox and refresh its display

Dr. Ahmed Alnasheri 14/17


2. EndUpdate: Resumes the updating of the ComboBox control after it has been temporarily
suspended.

comboBox1.BeginUpdate(); // Begin updating the ComboBox

// Update the ComboBox items

comboBox1.EndUpdate(); // End updating the ComboBox and refresh its display

3. FindString: Searches for the first item in the ComboBox that starts with the specified string.

int index = comboBox1.FindString("Item"); // Find the index of the first item that starts with

"Item"

These additional properties, events, and methods provide further functionality and control over
the ComboBox control in Windows Forms. You can explore their usage and adapt them to meet your
specific application requirements.

Here are some additional details about the ComboBox control in Windows Forms:

Properties:

1. DropDownWidth: Gets or sets the width, in pixels, of the drop-down portion of the ComboBox.

comboBox1.DropDownWidth = 200; // Set the width of the drop-down portion to 200 pixels

2. SelectedValue: Gets or sets the value of the selected item in the ComboBox.

comboBox1.SelectedValue = "Value1"; // Set the selected value of the ComboBox

object selectedValue = comboBox1.SelectedValue; // Get the selected value of the ComboBox

3. Sorted: Gets or sets a value indicating whether the items in the ComboBox are sorted.

comboBox1.Sorted = true; // Sort the items in the ComboBox

Events:

1. Validating: Occurs when the ComboBox is validating its contents.

comboBox1.Validating += ComboBox1_Validating;

private void ComboBox1_Validating(object sender, CancelEventArgs e)

// Handle the validating event

2. Validated: Occurs when the ComboBox has successfully validated its contents.

comboBox1.Validated += ComboBox1_Validated;

Dr. Ahmed Alnasheri 15/17


private void ComboBox1_Validated(object sender, EventArgs e)

// Handle the validated event

Methods:

1. DeselectAll: Deselects any selected items in the ComboBox.

comboBox1.DeselectAll(); // Deselect all selected items in the ComboBox

2. GetItemHeight: Retrieves the height of an item in the ComboBox.

int itemHeight = comboBox1.GetItemHeight(0); // Get the height of the first item in the

ComboBox

3. GetItemRectangle: Retrieves the bounding rectangle for an item in the ComboBox.

Rectangle itemRect = comboBox1.GetItemRectangle(0); // Get the bounding rectangle for the

first item in the ComboBox

These additional properties, events, and methods provide further functionality and control over
the ComboBox control in Windows Forms. You can explore their usage and adapt them to meet your
specific application requirements.

Here are some additional details about the ComboBox control in Windows Forms:

Properties:

1. DropDownHeight: Gets or sets the height, in pixels, of the drop-down portion of the ComboBox.

comboBox1.DropDownHeight = 150; // Set the height of the drop-down portion to 150 pixels

2. Text: Gets or sets the text associated with the ComboBox.

string text = comboBox1.Text; // Get the text of the ComboBox

comboBox1.Text = "New Text"; // Set the text of the ComboBox

3. SelectedValuePath: Gets or sets the path of the property to use as the value for the selected
item.

comboBox1.SelectedValuePath = "ID"; // Set the selected value path to the "ID" property of the

items

Events:

1. TextUpdate: Occurs when the text in the editable portion of the ComboBox has been updated.

comboBox1.TextUpdate += ComboBox1_TextUpdate;

Dr. Ahmed Alnasheri 16/17


private void ComboBox1_TextUpdate(object sender, EventArgs e)

// Handle the text update event

2. DropDownClosed: Occurs when the drop-down portion of the ComboBox is closed.

comboBox1.DropDownClosed += ComboBox1_DropDownClosed;

private void ComboBox1_DropDownClosed(object sender, EventArgs e)

// Handle the drop-down closed event

Methods:

1. SelectIndex: Selects the item at the specified index in the ComboBox.

comboBox1.SelectIndex(3); // Select the item at index 3 in the ComboBox

2. GetSelectedValue: Retrieves the value of the selected item in the ComboBox.

object selectedValue = comboBox1.GetSelectedValue(); // Get the value of the selected item in

the ComboBox

3. ResetText: Resets the text displayed in the editable portion of the ComboBox to its default
value.

comboBox1.ResetText(); // Reset the text displayed in the ComboBox

These additional properties, events, and methods provide further functionality and control over
the ComboBox control in Windows Forms. You can explore their usage and adapt them to meet your
specific application requirements.

Dr. Ahmed Alnasheri 17/17

You might also like