I'm trying to disable a few items dynamically from a Listbox. I used the following code:
How To Disable Selected Item In List Box
But, all I see is System.Data.DataRow in the Listbox, not the actual string.
I tried adding new BindingContext()
lbInsTypes.BindingContext = new BindingContext();
Also,
lbInsTypes.DataBindings.Add("DisplayMember", dtInsType, "InsuranceDescription", false, DataSourceUpdateMode.OnPropertyChanged);
but nothing worked.
DataSet dsInsType = db.GetAllInsuranceTypes(InstutionId);
lbInsTypes.DisplayMember = "InsuranceDescription";
lbInsTypes.ValueMember = "InsuranceTypeId";
lbInsTypes.DataSource = dsInsType.Tables[0];
I want to see the actual InsuranceDescription values in the ListBox from the table. Please show me how to use datasource with custom ListBox control.
Related
I'm creating a windows application and I want to show combo box value by filtering from the user input value. There is a property called AutoComplete but I'm assigning values for comboBox items using an object. So I couldn't fill AutoCompletedSource. How can I assign my item list to it?
There are two main ways to get autocomplete on a combo box. The first is to set the source to the comboBox.Items:
comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBox1.Items.AddRange(new []{"Omg", "So Kewel"," I love it"});
The second is to set up a custom source. In the second case the drop down arrow will reveal nothing but the autocomplete will show when you start typing.
comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
var list = new List<string>() {"Omg", "So Kewl", "I love it"};
var collection = new AutoCompleteStringCollection();
collection.AddRange(list.ToArray());
comboBox1.AutoCompleteCustomSource = collection;
I have created a checkboxlist and dynamically it displays value of the list.
But I need to design as per the image shown. What css class or which option to be used to achieve this.
listcontents.Add(thisQ.Option.ToString());
//CheckBoxList CB = new CheckBoxList();
CheckBoxList1.DataSource = listcontents;
CheckBoxList1.DataBind();
I have this problem for days and can't find solution for it. I tried all possible solutions i found on internet, but seems like none suits this one.
Thing is that i added repository item to gridControls (i added it through designer, not through code). Then, in code i added data source to that repository lookUpEdit and i have items in dropDown in that column. But when i select item in repository and click on other cell, Selected item in repository is cleared and repository shows null value again...
Any ideas what i did wrong ?
EDIT:
Also, when i click on any cell in my grid, i have delay of second or two, and after that delay clicked cell is focused... Any solutions for all of this?
EDIT:
Don't know what code to show You, because I did all in devExpress designer. Here is part of the code where I set data source to repository item, and i will give You code from designer of that repository item.
private void ConfigureRepositoryItems()
{
BetService.SportManagerClient dbSportManager = new BetService.SportManagerClient();
BetService.BLOddsControlSettings[] oddsControlSettings = dbSportManager.GetOddsControlSettings("", "");
repositoryOddsControlSettings1.DataSource = oddsControlSettings;
}
And here is code from designer:
//
// repositoryOddsCalculationSettings1
//
this.repositoryOddsCalculationSettings1.AutoHeight = false;
this.repositoryOddsCalculationSettings1.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
this.repositoryOddsCalculationSettings1.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
new DevExpress.XtraEditors.Controls.LookUpColumnInfo("ID", "ID", 20, DevExpress.Utils.FormatType.None, "", false, DevExpress.Utils.HorzAlignment.Default),
new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Name", "Name")});
this.repositoryOddsCalculationSettings1.DisplayMember = "Name";
this.repositoryOddsCalculationSettings1.Name = "repositoryOddsCalculationSettings1";
this.repositoryOddsCalculationSettings1.NullText = "Select Settings";
this.repositoryOddsCalculationSettings1.PopupSizeable = false;
this.repositoryOddsCalculationSettings1.ValueMember = "ID";
For starters check whether the column name in your Grid datasource and the column in your grid control match. The match is case sensitive so name and Name are not same and hence can cause this issue. Secondly make sure the Grid datasource column datatype matches the value type of the LookUpEdit. If the LookupEdit is returning int and the Grid datasource column datatype is string, this alone can cause lots of headaches.
I would like to set a value to the ComboBox in the DataGridView. I already have changed the comboBoxItems, I just want to select one of them. Thank you in advance!!!
I already solved my problem... I'm gonna post the way I did and hoppefully someone will find this answer too.
dgrDetalle.DataSource = dataTable("select * from yourTable");
DataTable dtCombo = dataTableCombo("select COL_ID DETOC_COL_FK,COL_DESCRIPCION from yourTable2");
string[] strColumns = new string[] { "COL_DESCRIPCION" };
MultiColumnDictionary map = new MultiColumnDictionary(dtCombo, "DETOC_COL_FK", strColumns, 0);
dgrDetalle.Cols["DETOC_COL_FK"].DataMap = map;
As you can see the class that save my life is MultiColumnDictionary.
Note: The combobox items must be loaded in a different DatatTable than the DataTable that is gonna load directly in the grid.
As far as I know, the Comboboxes only actually exist as controls when they are being edited, and therefore don't have a selected item property.
You can simply set the Value property of the cell to the item you want selected, or alternitively, you can set a default value by setting the property:
DataGridViewColumn.DefaultCellStyle.NullValue.
I have ListBox data bind to list of users (collection):
usersListBox.DataSource = null;
usersListBox.DataSource = _users;
usersListBox.DisplayMember = "Name";
usersListBox.ValueMember = "Id";
Now I want properties of selected item to be shown in different text boxes, so I do the binding:
nameTextBox.DataBindings.Add("Text", usersListBox.SelectedItem, "Name");
loginTextBox.DataBindings.Add("Text", usersListBox.SelectedItem, "Login");
When form load I can see that values of selected item appear in textboxes, but when selected item in listBox is changed, values in text boxes are still the same. Do I have to catch selectedItemChanged of listbox and repeat binding of textboxes? Or I'm missing something and values in textboxes should change with changing selected item?
If someone needs answer: you have to create binding source object and assign it list box and textboxes:
usersBindingSource = new BindingSource();
usersBindingSource.DataSource = _presenter.Users;
usersListBox.DataSource = usersBindingSource;
usersListBox.DisplayMember = "Name";
usersListBox.ValueMember = "Id";
nameTextBox.DataBindings.Add("Text", usersBindingSource, "Name", true, DataSourceUpdateMode.OnPropertyChanged);
loginTextBox.DataBindings.Add("Text", usersBindingSource, "Login", true, DataSourceUpdateMode.OnPropertyChanged);