Browse by Tags
All Tags » ComboBox (RSS)
-
|
ComboBox loading performance issues are generally related to loading the data multiple times. The two most common scenarios for this are setting the DisplayMember after setting the DataSource or binding the ComboBox prior to filling the DataSource. Setting...
|
-
|
ComboBox binding does not directly support data source property concatenation however you can use the ComboBox Format event to concatenate multiple data source properties. Sample: Concatenating data source properties using the Format event (VS 2005) ...
|
-
|
When data bound, the Windows Forms ComboBox does not provide a general way to add a "null" or "not selected" value to its items list. The only generally supported way to do this is to add a "null" item to your data source...
|
-
|
A common use of a ComboBox in a data bound application is as a lookup based UI control. From a database perspective, a Lookup control is used to provide the "lookup" values for a foreign key. For example, assume you have a customer table with...
|
-
|
You can fill a ComboBox with non-string items such as business objects. By default, the ComboBox will call ToString() on each of the items to generate the display text (visible text). Rather than rely on ToString(), you can have the ComboBox use one of...
|
-
|
Use the FindStringExact method. For example, to set the ComboBox's ValueMember property to "OrderID", then you could call comboBox1.SelectedIndex = comboBox1.FindStringExact( stringOrderID ); where stringOrderID is the orderID of the row...
|
-
|
Michael Gold discusses this problem in his article How to create a "ComboBox button" in a toolbar in .NET on C# Corner . Contributed from George Shepherd's Windows Forms FAQ
|
-
|
You can subclass ComboBox. In your derived class, make sure you set DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; DropDownStyle = ComboBoxStyle.DropDownList; You also need to handle the DrawItem event to actually implement the drawing. Check...
|
-
|
You can prevent the ComboBox dropping by overriding its WndProc method and ignoring the WM_LBUTTONDOWN and WM_LBUTTONDBLCLK. [C#] using System.Windows.Forms; public class CustomComboBox : ComboBox { protected override void WndProc( ref Message m ) { if...
|
-
|
You can iterate through the list to find the longest text extent using MeasureString, and then use this as the ComboBox width adding a fudge factor for the drop-down button. using ( Graphics g = comboBox1.CreateGraphics() ) { float maxWidth = 0f; foreach...
|
-
|
You can control the height by changing the value of the MaxDropDownItems property of the the ComboBox, which is the maximum number of entries that will be displayed in the drop-down list. Contributed from George Shepherd's Windows Forms FAQ
|
-
|
Set the ComboBox's DropDownStyle property to DropDownList. Contributed from George Shepherd's Windows Forms FAQ
|
-
|
Here are some snippets. (Courtesy of) [C#] DataTable list = new DataTable(); list.Columns.Add(new DataColumn("Display", typeof(string))); list.Columns.Add(new DataColumn("Id", typeof(int))); list.Rows.Add(list.NewRow()); list.Rows...
|
-
|
The enum values can be bound to a combobox as follows: MyValues is the enum type [C#] // Setup the binding as follows: comboBox1.DataSource = Enum.GetValues(typeof MyValues); // SelectedValueChanged event for the ComboBox. private void ComboBox1ValueChanged...
|
-
|
Try comboBox1.Items.AddRange( FontFamily.Families ); Contributed from George Shepherd's Windows Forms FAQ
|