We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Comboboxes and Data sources...

Thread ID:

Created:

Updated:

Platform:

Replies:

5155 Jun 22,2003 05:52 PM Jun 23,2003 01:26 AM Windows Forms 4
loading
Tags: GridControl
Denis
Asked On June 22, 2003 05:52 PM

Hi, I have a collection of objects which I am trying to use as a datasource for my grid (1 row per object). My problem is that I dont know how to populate the combobox with options, and then have the combobox select the value that each object holds. Grid.Item(Row, 3).CellType = "ComboBox" Grid.Item(Row, 3).DataSource = MyObject Grid.Item(Row, 3).DisplayMember = "ItemType" Grid.Item(Row, 3).ValueMember = "idItemType" Grid.Item(Row, 3).ExclusiveChoiceList = True If you can imagine the scenario above .... the property "ItemType" is the description I want them to select, but idItemType is the value that needs to be stored (ItemType is a readonly string property). How do I populate the combo with values and then have it default to the value of the object it is bound to? eg. 1 CPU 2 Motherboard 3 RAM 4 Network if MyObject.idItemType = 3, then the combobox should say "RAM" Thanks

Administrator [Syncfusion]
Replied On June 22, 2003 07:31 PM

> Hi, > > I have a collection of objects which I am trying to use as a datasource for my grid (1 row per object). My problem is that I dont know how to populate the combobox with options, and then have the combobox select the value that each object holds. > > Grid.Item(Row, 3).CellType = "ComboBox" > Grid.Item(Row, 3).DataSource = MyObject > Grid.Item(Row, 3).DisplayMember = "ItemType" > Grid.Item(Row, 3).ValueMember = "idItemType" > Grid.Item(Row, 3).ExclusiveChoiceList = True > > If you can imagine the scenario above .... the property "ItemType" is the description I want them to select, but idItemType is the value that needs to be stored (ItemType is a readonly string property). How do I populate the combo with values and then have it default to the value of the object it is bound to? > > eg. > 1 CPU > 2 Motherboard > 3 RAM > 4 Network > > if MyObject.idItemType = 3, then the combobox should say "RAM" > > Thanks What you could do is create a class that has public properties for idItemType and ItemType. The properties should be public and browsable. E.g: public class MyData { private string id; private string desc; public string idItemType { get { return id; } } public string ItemType { get { return desc; } } } Then populate the collection, e.g. ArrayList al = new ArrayList(); al.Add(new MyDataSource(1, "RAM")); ... then you can assign this collection to a combobox: Grid.Item(Row, 3).CellType = "ComboBox" > Grid.Item(Row, 3).DataSource = al > Grid.Item(Row, 3).DisplayMember = "ItemType" > Grid.Item(Row, 3).ValueMember = "idItemType" > Grid.Item(Row, 3).ExclusiveChoiceList = True Stefan

Denis
Replied On June 22, 2003 11:13 PM

Thanks for your reply Stefan ... I understand what you are saying, however I dont want to use the arraylist object as the datasource. This does give me the drop down list as expected, however the values are not bound to the idItemType property of my MyObject class .. ie. when the combo is changed, the value in my class is not changed. Here is the code I have implemented so far: Dim arylst As New ArrayList() arylst.Add(New cComboboxDisplay("Left", CP_Just_Left)) arylst.Add(New cComboboxDisplay("Centre", CP_Just_Centre)) arylst.Add(New cComboboxDisplay("Right", CP_Just_Right)) Grid(Row, COL_Justification).CellType = "ComboBox" Grid(Row, COL_Justification).DataSource = arylst Grid(Row, COL_Justification).DisplayMember = "DisplayMember" Grid(Row, COL_Justification).ValueMember = "ValueMember" Grid(Row, COL_Justification).ExclusiveChoiceList = True This does give me the combobox with values, however I then have to have interpreting code to fill the values from the class to the combobox .. ie. Select Case Justification Case CP_Just_Centre Grid.Item(Row, COL_Justification).Text = "Centre" Case CP_Just_Left Grid.Item(Row, COL_Justification).Text = "Left" Case CP_Just_Right Grid.Item(Row, COL_Justification).Text = "Right" End Select whereas I was hoping to bind the combo to the object from MyClass and provide it with an arraylist of options ... it is probably not possible now that I think of it :/ Thanks again, D.

Denis
Replied On June 22, 2003 11:21 PM

ps. I tried to use Grid.Item(Row, COL_Justification).CellValue = Justification instead of that case statement, but it doesnt seem to work. Reading from ".CellValue" seems to work though, so a case isnt required when reading the value back into the class manually. D.

Administrator [Syncfusion]
Replied On June 23, 2003 01:26 AM

Is Grid a virtual grid where you provide values in QueryCellInfo? If so, you woul dhave to handle SaveCellInfo to move changes values back to your datasource for Grid. If you don't do this, this would explain why trying to assign Grid.Item(Row, COL_Justification).CellValue does not work. Another thing to check is whether the cell at (Row, COL_Justification) is ReadOnly. If it is you would have to set Grid.IgnoreReadOnly = true while you try to change its value.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;