Home Forums WinForms controls Xceed Grid for WinForms getfittedwidth-method for unbound detailgrids

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

    Hi everyone,

    I have built an unbound master-detail-grid.
    (like the examples in the .Net-Grid-documentation)

    I am using the getfittedwidth-method after filling the master-grid with unbound data:
    For Each column in GridControl1.Columns
    column.Width = column.GetFittedWidth()
    Next column
    That works fine.

    I also want to fit the width of the columns of the detailgrid,
    I am using the getfittedwidth-method after filling the detailgrid with unbound data:
    For Each column in detailgrid.Columns
    column.Width = column.GetFittedWidth()
    Next column
    -> but that has no effect: the columns of the detailgrid are not fitted!!

    Does anyone have a sample or something that would help me?

    Thank you in advance.

    vUser

    Imported from legacy forums. Posted by VUser (had 4637 views)

    User (Old forums)
    Member
    Post count: 23064

    This should work fine. It is possible that you do it on the DetailGridTemplate instead of the actual DetailGrid.

    Imported from legacy forums. Posted by André (had 475 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello AndreC
    thanks for your answer!

    What is the right syntax to get the created detailgrid, not the template?
    Here is my code to add the detailgrid to GridControl1:

    detail = New Detailgrid
    …(adding columns, stylesheets)…
    Me.GridControl1.DetailGridTemplates.Add(detail)

    GridControl1.EndInit()

    …- after filling the cells with contents, at last this sub is called:
    call GridColumnwidth(detail)

    Private Sub GridColumnwidth(ByVal obj As DetailGrid)
    Dim column As Column
    For Each column In obj.Columns
    column.Width = column.GetFittedWidth()
    Next column
    End Sub

    Do you know what is wrong?

    thanks
    VUser

    Imported from legacy forums. Posted by VUser (had 405 views)

    User (Old forums)
    Member
    Post count: 23064

    The DetailGrid instance is on the row itself.

    //if you don’t already have the row, you can use the CurrentRow
    //this will throw if not on a DataRow, so you need to make a safe cast
    Xceed.Grid.DataRow row = gridControl1.CurrentRow as Xceed.Grid.DataRow;
    if ( row != null )
    {
    //get the DetailGrid
    DetailGrid detail = row.DetailGrids[ 0 ];
    foreach( Column col in detail.Columns )
    {
    col.Width = col.GetFittedWidth();
    }
    }

    Imported from legacy forums. Posted by André (had 441 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks a lot!
    This was exactly what I needed!

    Imported from legacy forums. Posted by VUser (had 413 views)

    User (Old forums)
    Member
    Post count: 23064

    I’ve got the same problem, see code below…

    Dim ds As System.Data.DataSet = pageView.Runtime.DataSet
    Dim table As String = pageView.Table.Name
    Dim strTemp As String = “”
    Dim intTemp As Integer
    Dim details As DetailGrid

    objForm.XceedGridControl.BeginInit()

    objForm.XceedGridControl.SetDataBinding(ds, table)

    ‘ Bind any pageview children
    If pageView.Child IsNot Nothing Then
    ‘ Add the child pageviews
    details = New DetailGrid
    details.SetDataBinding(pageView.Child.Runtime.DataSet, pageView.Child.Table.Name)
    details.HeaderRows.Add(New ColumnManagerRow())
    objForm.XceedGridControl.DetailGridTemplates.Add(details)
    End If

    objForm.XceedGridControl.EndInit()

    If pageView.Child IsNot Nothing Then
    For Each df As DisplayField In pageView.Child.Fields
    ‘ Styling
    intTemp = objForm.XceedGridControl.DetailGridTemplates.Item(0).Columns.df.DataField).GetFittedWidth
    objForm.XceedGridControl.DetailGridTemplates.Item(0).Columns(df.DataField).ReportStyle.Width = CInt(intTemp + (intTemp / 10))

    Next
    End If

    objForm.XceedGridControl.UpdateDetailGrids()

    The columns seem to size only by the columns headerrow rather than the contents of the each of the cells in the columns. Any ideas?

    Imported from legacy forums. Posted by Mark (had 465 views)

    User (Old forums)
    Member
    Post count: 23064

    You call the GetFittedWidth on the template, before it is filled with actual data, which explains the result you get. So the template is set to the header width, since this is the only thing that is present, and this is the width that is used when generating the actual DetailGrids from the template.

    You need to do this once the DetailGrid is actually created and filled with data. In the code I provided before, you can see that a specific DetailGrid instance is taken from a specific row, and this works fine.

    i.e.:

    //get the DetailGrid
    DetailGrid detail = row.DetailGrids[ 0 ];

    Imported from legacy forums. Posted by André (had 5473 views)

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