I have an ultragrid populated by a blank "department" class: Dim AffDeptList As New BindingList(Of PTWAffDeptHeads)
This grid has 2 dropdowns, 1st one for departments and 2nd for people. (their datasources are populated by a stored procedure)
I can add rows (new dept and people) to the grid ok. I use the AddNew box to add new rows to the grid (and make my selections for the 2 dropdowns) and then save. the row data is successfully saved to the database.
But I need to have the grid populated from a datasource. So that the grid will list all the rows that were selected/saved. each row has a dropdown of a selected dept and a selected person that should show the selected value.
Here's how I'm loading my grid, and 2 dropdowns.
Dim PTWId As Guid 'Fill Grid GridAffDepts.DataSource = AffDeptList
'Fill Dept DropDown Dim ds As System.Data.DataSet ds = DataAccess.LoadDepts(formId)
ddlDept_AffDeptList.SetDataBinding(ds, Nothing, True) ddlDept_AffDeptList.ValueMember = "DeptId" ddlDept_AffDeptList.DisplayMember = "DeptName"
cboDept_AffDeptList.ValueMember = "DeptId" cboDept_AffDeptList.DisplayMember = "DeptName" cboDept_AffDeptList.DataSource = ds.Tables(0)
'Fill POB DropDown ds = DataAccess.SelectPerson(formId) ddlPOB_AffDeptList.SetDataBinding(ds, Nothing, True) ddlPOB_AffDeptList.ValueMember = "PersonId" ddlPOB_AffDeptList.DisplayMember = "FullName"
Here's one of the datasources I would use to populate the dept. basically the "chkselected" will be 1 if the row is selected, 0 if not:
SELECT d.DeptId, d.DeptCode, d.DeptName, CASE WHEN ad.formid = @formid THEN 1 ELSE 0 END [chkSelected] FROM VW_Department d LEFT JOIN PTWdepts ad ON ad.PTWDeptId = d.DeptId AND (ad.formid = @formid OR @formid = '00000000-0000-0000-0000-000000000000') ORDER BY DeptName
Not sure how to auto popluate the grid with the selected rows from a datasource.
Hi,
I'm having trouble understanding what you are asking.
It sounds like you are currently binding the grid to a BindingList<T> and you are asking how to bind the grid to a DataSet populated from a server or other database.
But you are already populating the dropdowns using a DataSet (presumably from a database). And there's no difference between doing this for a DropDown or a grid.
So I don't know what your question is.
Yes i have successfully binded the grid to a DataSet populated from a server or other database. and I have 2 columns in my drid that are ultradropdowns. i want each column to have a selected row/value based on the dataset. so when you are viewing the grid, the dropdowns are set at the selcted position. I'm not sure how to add a new row to the grid (or rows) first of all. secondly, I need to also make sure the dropdowns in the grid reflect the datasource values. Note, the grid is empty until the user clicks the addnew button, then a new row is created. but I'd like to dynamically add this row(s) based on my datasource.