Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14113 |

    Guys, I’m trying to create a detail grid on the fly such that I add a datarow to a grid for each object I have in a collection. If each of these objects has a subobject, then I would like a detail grid to display this info. The code I have written is below but I cannot get it to work. Any help would be greatly appreciated.

    GridSamples.DataRows.Clear()
    GridSamples.BeginInit()
    ‘just a 3 columns for now to take some sample details
    GridSamples.Columns.Add(New Xceed.Grid.Column(“Sample Name”))
    GridSamples.Columns.Add(New Xceed.Grid.Column(“Sample Number”))
    GridSamples.Columns.Add(New Xceed.Grid.Column(“MolWgt”))
    ‘now go through each row adding relevant details in a new row
    For Each Sample As AMSCore.Sample In ReqSamples
    Dim MyRow As Xceed.Grid.DataRow = GridSamples.DataRows.AddNew
    MyRow.Cells(“Sample Name”).Value = CType(Sample.SampleName, String)
    MyRow.Cells(“Sample Number”).Value = CType(Sample.SampleNumber, String)
    MyRow.Cells(“MolWgt”).Value = CType(Sample.MolWeight, String)
    ‘now if we have some availability data, we’ll show it in a details grid
    If Sample.Availabilites.Count > 0 Then
    Dim MyAvailGrid As New Xceed.Grid.DetailGrid
    MyAvailGrid.HeaderRows.Add(New Xceed.Grid.ColumnManagerRow)
    MyAvailGrid.Columns.Add(New Xceed.Grid.Column(“Amount”))
    MyAvailGrid.Columns.Add(New Xceed.Grid.Column(“Units”))
    MyAvailGrid.Columns.Add(New Xceed.Grid.Column(“Dispensary”))
    For Each Avail As AMSCore.Availability In Sample.Availabilites
    Dim AvailRow As Xceed.Grid.DataRow = MyAvailGrid.DataRows.AddNew
    AvailRow.Cells(“Amount”).Value = CType(Avail.Amount, String)
    AvailRow.Cells(“Units”).Value = CType(Avail.Units, String)
    AvailRow.Cells(“Dispensary”).Value = CType(Avail.Dispensary, String)
    AvailRow.EndEdit()
    Next
    GridSamples.DetailGridTemplates.Add(MyAvailGrid)
    End If
    MyRow.EndEdit()
    Next
    GridSamples.EndInit()
    GridSamples.UpdateDetailGrids()

    Imported from legacy forums. Posted by Chris (had 5457 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    You can’t selectively have detail grids for certain rows and not for others, they will be displayed even if they contain no rows.

    In which case I suggest you add all your columns and DetailGridTemplates before you add any rows.

    Imported from legacy forums. Posted by IdleHand (had 172 views)

    User (Old forums)
    Member
    Post count: 23064

    Cheers Idlehand, but I’m not sure what you mean. I don’t mind having detail grids with nothing in but I can’t even get them to display properly. Are you saying that in my loop, I should create a detailgrid first then add rows to it, then add to the templates before creating datarows in the maingrid? Many thanks for you reply

    Imported from legacy forums. Posted by Chris (had 349 views)

    User (Old forums)
    Member
    Post count: 23064

    The trouble is you can not add rows directly to a detail grid template, you need to add rows to an instance of the template, either when it is initialised or expanded.

    If you are trying to get to grip with the basics, I suggest you look at the Xceed.Grid Documentation that came with your installation under <b>Task-Based Help > Data binding and editing > How to display unbound hierarchical master/detail data.</b>

    Imported from legacy forums. Posted by IdleHand (had 428 views)

    User (Old forums)
    Member
    Post count: 23064

    Again, many thanks IdleHand. I did follow the info in the document but it doesn’t quite match my needs as I’m populating the detail grid in an iterative loop. I’m obviously a bit confused an was hoping for a pointer as to where I’m going wrong. In the document they populate their detailgrid in an eventhandler but I don’t need to do it that was as I’ll have all sorts of problems tracking my object etc. Thanks again for your assistance and any further help will be greatly appreciated

    Imported from legacy forums. Posted by Chris (had 745 views)

    User (Old forums)
    Member
    Post count: 23064

    Well, I would recommend populating your detail grids in an event handler, it shouldn’t be that complicated if your objects are well designed.

    However, if you don’t then I guess you can iterate through your grid’s DataRows, something like this:

    1. Add columns to grid
    2. Create <b>single</b> DetailGridTemplate
    3. Add columns to detail grid template
    4. Add detail grid template to grid
    5. Add rows to grid
    6. Iterate through DataRows of grid:
    —- Use dataRow.DetailGrid to obtain instance of DetailGridTemplate
    —- Add rows to detail grid instance

    Please note, I haven’t tried this, but it may work.

    Imported from legacy forums. Posted by IdleHand (had 420 views)

    User (Old forums)
    Member
    Post count: 23064

    Cheers IdleHand, I’ll give that a go and let you know how I get on. It wont be til tomorrow now. Once again, many thanks for your help, it’s greatly appreciated

    Imported from legacy forums. Posted by Chris (had 368 views)

    User (Old forums)
    Member
    Post count: 23064

    IdleHand, you are a star matey, your suggestion worked an absolute treat. Many thanks for you time in answering my query and I now understand where I went wrong.
    Thanks again

    Imported from legacy forums. Posted by Chris (had 383 views)

    User (Old forums)
    Member
    Post count: 23064

    You’re welcome, glad to hear it worked 😉

    Imported from legacy forums. Posted by IdleHand (had 6556 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.