Hi all,
I have a ultragrid let user to update directly, I would like to set 1 of the column as dropdown selection to update data. The data of the dropdown will be get from a data source, how should I code for this condition?
I found from the community, most of the sample is assign data with hardcode method like below, can you all please suggest me a method which data retrive by data source?
private void BindUltraDropDown(){ DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(int)); dt.Columns.Add("DisplayText", typeof(string)); dt.Rows.Add(new object[] {1, "A"}); dt.Rows.Add(new object[] {2, "B"}); dt.Rows.Add(new object[] {3, "C"}); dt.AcceptChanges(); this.ultraDropDown1.SetDataBinding(dt, null); this.ultraDropDown1.ValueMember = "ID"; this.ultraDropDown1.DisplayMember = "DisplayText";}Thank you very much!
The sample you reference here is getting a ValueList, which is populated in code.
If you want to populate your list from a data source, then you can use the BindableValueList class and then bind it to a DataSource just as you would any other control (like the grid), using the DataSource and DataMember properties.
In addition, you will probably also want to set the ValueMember and DisplayMember on the BindableValueList.
If you want a multi-column dropdown, you could do the same thing using the UltraDropDown control. Once again, you bind it in exactly the same way you bind the grid.
Hi Mike,
Thanks for your reply. Actually I know how to bind grid with datasource, but I would like to know what should I do if I want to make one of the column in the grid become a dropdown list, and the dropdown list data coming from another datasource.
I found this from sample explorer, in the source, it add the value list one by one in the GetStateValueList(), it will not suitable for my condition, because my dropdown will be maintain from database and keep update time to time, so I would like to know is it other way to do the same thing like this sample but for a single column only.
Please guide.
Thank you very much!
Hi,
This code is creating a DataTable in code and assigning it to the UltraDropDown as it's data source.
If you want to get your data from a database, instead, then there are a number of ways you can do that, but none of them really have anything to do with the grid or the DropDown. For detailed documentation on how to retrieve data from a database, you will need to check Microsoft's documentation.
The typical way to do it using DataSets and DataTable is to use the DataAdapter class to fill those objects via a Connection.
Binding the UltraDropDown and binding the WinGrid (or any other control) is essentially the same, though. So you could check the online help and I am pretty sure there are a couple of simple examples of how to bind the grid to a data source using an Access database file or SQL Server.
Here's a link to the help where this is discussed.
Accessing Data