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 <><
I had two issues. First, the Key for my second and should have been the name of the relation (FM_TASK) and the second problem is that I had a column in my design that was not in my table. I just figured that it would just disreguard it and move on. I guess not.
Mark <><
While I completely agree with you, I'm not sure what to change it to? As you can see from my code, I have two tables in a parent/child relationship. The parrent table is identified as "FM", the child table is refered to as "Task". Those are the exact names that I have set as the Key property in the designer. My guess is that I need to refer to my second table as something other than "Task". So, based on the following dataset, what should I set the Key property for my bands?
Dim daFM As OleDbDataAdapter = New OleDbDataAdapter(lSQL_FM, con) Dim dsFM As DataSet = New DataSet daFM.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)
I've added a shot of my designer to show the values of the first and second band. Also, I've tried the RowLayout approach but right now I'm trying to figure out how to apply a layout at runtime.
Hi Mark,
It sounds to me like something is not matching up. Either the column names, band names, or column data types on the child band must be different between run-time and design-time. My guess is the band name, that's the most common mistake people make when setting up the grid at design-time.
You might want to check the Key of each band in the grid at run-time to make sure you are using the correct band keys in your design-time layout.