How do I set combobox text - wpf

lets say I have combobox and I have set data source (string list) to it. I don't want to include - Select - to the list. is it possible to display - Select - on dropdown without adding it to datasource. (Is it possible to display text which is not in the list?)

You can make combobox editable and readonly and then set its text.
.IsEditable = True
.IsReadOnly = True
.Text = "----Select----"

Related

changing the DisplayMember of Syncfusion ComboBoxAutoComplete

I am working with Syncfusion tools, and am trying to add a ComboBoxAutoComplete control to a Windows form. I have a DataTable that I'm using as my DataSource with two columns: ID and Name. I set the DataSource, DisplayMember, and ValueMember properties like so:
ComboBox1.AutoCompleteControl.DataSource = table
ComboBox1.DisplayMember = "Name"
ComboBox1.ValueMember = "ID"
The control loads correctly, but it appears that the DisplayMember does not get applied. The control will display only the ID of the selected item. When I expand the drop-down, it displays the entire table (both columns). I tried setting the DisplayMember and ValueMember directly on the AutoCompleteControl, but those properties do not exist. Is there a different property that is used to control what text is displayed in the ComboBoxAutoComplete control?
We have prepared the simple sample in which we have assigned data table to "DataSource" property of AutoCompleteControl inside the ComboBoxAutoComplete to enable the AutoComplete features.
To display the value based on DisplayMember assigned the Data table columns to “Columns” (collection property) of AutoCompleteControl and set “MatchingColumn” value as True for which column has been set in DisplayMember.
Please check with the sample from below location.
Sample: ComboBoxAutoComplete_Sample
Regards,
Keerthana J

Set ComboBox text from Items only

I am trying to set a ComboBox's text conditionally - that is, if the text I am setting it to exists in the box's Items, then set it to that. Otherwise, leave it blank.
e.x.
ComboBox's Items:
Green
Blue
Pink
Red
For ComboBox1 I am trying to set to "Red". Because that string exists in the Items, the text property is set to "Red". For ComboBox2 I am trying to set to "Yellow", which doesn't exist, so I want that text empty (but the previous items still are there).
All the comboboxes will have the same Items. However, there are lots of combo's so I'm trying to avoid looping through each boxes owns items and compare each one. In C# you could just do something like:
ComboBox1.ItemIndex := 'My Text';
Which doesn't compile here.
You could use either
ComboBox1.ItemIndex := ComboBox1.Items.IndexOf('My Text');
or
ComboBox1.Text := 'My Text';
The second version requires that you have ComboBox's Style set to csDropDownList (otherwise the string would be shown in the combobox even if it is not in the list).

Devexpress checkbox column in a gridcontrol c#

I have a datagrid from devexpress in a winform application.I populated the datagrid from code (datasource=my datatable with 2 strings columns and one of type int (receive 0 and 1 values-should be checkbox on form).
I added a datagrid and from designer I added 3 columns.The last one of type checkbox.I set
UnboundType=Integer,
UnboundExpression=my column name from datatable :
DisplayFormat = Numeric,
columnedit = checkbox,
Displaycheckedvalue = 1,
displayuncheckedvalue = 0.
When I run the application always my checkboxes are blue.If i press one checkbox appear a check but when i go to the next row the previous value is again blue.What should i do so why the application keep the checks?
Don't set the column to be unbound, it is in your datasource after all.
What you want to do is just to set Displaycheckedvalue and displayuncheckedvalue as you have done, nothing more.
You can make a class which got a property for each column of your table. The int value would be a bool and so you can use List as datasource. The Grid will automaticly add checkboxes for the bool value.
If you want to use DataTable see Stig's post but in my opinion it is more beautiful to use classes and List.

how to use the display value of the Foxpro combobox

I have a combo box that I would like it to show a
category name ("Cat1" , "Cat2"...)
But when clicked or just displayed I would like to get the ID of this category. Any idea how to do this in Foxpro?
To populate your combobox:
Thisform.Combo1.AddItem("Cat1")
Thisform.Combo1.AddItem("Cat2")
You may use rowsource to add the entire item list into the combobox.
Get the selected value of combobox:
Thisform.Combo1.DisplayValue
Please refer to this article
Create a cursor that contains what you want to display in the first column and the ID in the second. Then, set up the combo like this:
RowSourceType = 2-Alias
RowSource = <your cursor name>
BoundColumn = 2
BoundTo = .T. && so you can have a numeric controlsource
Tamar

how to set selected item in ComboBox

This should be easy but Windows.Forms surprises me again:
var comboBox2 = new ComboBox();
comboBox2.Items.Insert(0,"Hoi");
comboBox2.Items.Insert(1,"Hoi");
comboBox2.Items.Insert(2,"Hoi");
comboBox2.SelectedIndex = 1;//I want to select the SECOND item
If I openup the combobox (by clicking on it with the mouse) the FIRST item is selected. This does not occur when the items have different texts. How can I select the second item on this combobox?
Use something like this,
comboBox2.Items.Insert(0,"Hoi");
comboBox2.Items.Insert(1,"Hui");
comboBox2.Items.Insert(2,"Hai");
and after this try giving
comboBox2.SelectedIndex = 1;
and also if you want select an item, always the index will starts from 0.
If you have a proper datasource set the following properties:
1. DataSource2. DisplayMember and 3. ValueMember
If you dont have the data source, try setting the following properties:
1. SelectedIndex and
2. Text

Resources