I have a WinGrid that needs to display a large number of columns. I'm binding to a datasourse at runtime so I can't design my layout at design time. How do I display my data on multiple lines (Levels). I was under the impression that there is no way to bind my data at runtime and still use the structure created at desing time. If that is true, I need to produce my structure at runtime.
Something like this:
Description
Name
Type
Code
Cost
Approved
Description 1
Bob
M
01
$12.00
Yes
Description 2
Mary
F
02
$14.25
No
You can set up your layout at design-time and use it at run-time. Here's a KB article that shows you how.
HOWTO:How can I define columns in the grid at Design-time and bind them at run-time so that some fields of the data are excluded from the grid?
The layout you have here is pretty simple, though, and you could probably do this more easily using Groups and Levels. Use the InitializeLayout event of the grid. Add one or more Groups to the band (band.Groups.Add). Then you have to assign each column to a group. In this case, you probably only need one group - Description. Then you can set LevelCount on on the band to 2 so each row is two levels and also set the Level property on each column.
There is still another way to do this, too. Since it looks like you just need everything on one line except one field (Description), then you could probably just use the RowAutoPreview functionality. The auto preview is not editable, though, so this method won't work if you need the description field to be editable by the user.
Dim daFM As OleDbDataAdapter = New OleDbDataAdapter(lSQL_FM, con)Dim dsFM As DataSet = New DataSetdaFM.Fill(dsFM, "FM")Dim daTask As OleDbDataAdapter = New OleDbDataAdapter(lSQL_TASK, con)daTask.Fill(dsFM, "Task")dsFM.Relations.Add("FM_TASK", dsFM.Tables("FM").Columns("ID"), dsFM.Tables("Task").Columns("FM_ID"))PackageGrid.SetDataBinding(dsFM.Tables("FM"), Nothing, True)
The grid will display two bands as expected and will even bind the columns to the first band. For example, if I change the column caption in the designer for one of the data columns in the first band [Bands(0)] the change is reflected in the runtime grid. The problem I'm having now is that any design changes I make to the second band [Bands(1)] are not reflected in the runtime grid.
Thanks for the assistance.
P.S. I've also posted this question in the Help Center hoping to get an answer as complete and quick as possible.
Mark Flach <><
Actually, my grid will be far more complex than the example I provided. My intent was to give a basic idea of what I'm doing. My actual grid will have two bands with the first band having 1 level and the second band having 3 levels.
lSQL = "SHAPE{" & lSQL_FM & "}" & _" APPEND ({ " & lSQL_TASK & "} as fmecaTASK RELATE 'ID' to 'FM_ID') as fmecaFM "
Dim rs As New ADODB.RecordsetDim da As OleDbDataAdapter = New OleDbDataAdapter(lSQL, con)Dim ds As DataSet = New DataSetda.Fill(ds)Dim dt As DataTabledt = ds.Tables("Table")PackageGrid.SetDataBinding(dt, Nothing, True)
I would really like to design my grid at design time and just set the datasource and call it a day. I've also tried to add the following code to no avail.
e.Layout.Bands(1).LevelCount = 2e.Layout.Bands(1).Columns("LOM").Level = 1
Any thoughts?
Mark <><