Question

I have a DevExpress XtraGrid.GridControl in a Winforms project that I'm using with a Master/Detail setup with multiple tables in a dataset that is bound at runtime. The visual behavior of the grid is somewhat erratic in that there is a dragable bar at the bottom of the visible grid section in the GridControl, that does not expand to the size of the control when the size of the data changes.

In my implementation, the GridControl is docked to fill the tab page that it occupies, and with this single exception works as expected. However the grid itself is only using half of the visible area available on the form. This is an issue because the data is over a full screen of rows and detail rows, but the user must manually resize the view by dragging the size bar to the bottom of the screen.

I'm manually expanding each view as they are registered, though this issue persists even when I do not automatically perform this and allow the user to expand them by clicking the plus sign. Here is the section of code that programmatically expands a view:

For x As Integer = 0 to v.RowCount - 1
  For y as integer = 0 to v.GetRelationCount(x) - 1
    v.ExpandMasterRow(x, y)
  Next
Next

I have looked for a way to set a GridView object to 'dock' inside the GridControl, but have not found a way to. Is there a way to make the data fill the GridControl/View automatically? Thank you for any assistance on this issue.

Was it helpful?

Solution 3

It seems that when the XtraGrid creates a sub view, it ignores the DetailHeight of the parent view, in favor of the DetailHeight on the child view. Setting the view's DetailHeight as it is registered corrected the problem.

Private Sub grdMaster_ViewRegistered(sender As System.Object, e As DevExpress.XtraGrid.ViewOperationEventArgs) Handles grdMaster.ViewRegistered
  Try
    Select Case e.View.GetViewCaption()
      Case "parent_child"
        Dim view As Grid.GridView = e.View
        view.DetailHeight = 10000
    End Select
  Catch ex As Exception
    'handle error.
  End Try
End Sub

Thank you all for your assistance and help.

OTHER TIPS

Usually you'll want to have a GridView for each DataTable you want to show in a GridControl, but when you do all in runtime, you will need to initialize the same Gridview for each datasource/DataTable you want to show.

//GridView view;
view.PopulateColumns();
view.OptionsView.ColumnAutoWidth = true;
view.BestFitMaxRowCount = 10000;   // or less ? depends on your data vs preformance
view.BestFitColumns();
// you may want to limit some of the columns width
foreach (GridColumn item in view.Columns)
{
    item.Width = (item.Width > 1000) ? 1000 : item.Width;
}
//GridControl ctrl;    // if you do this in form load you  need to do a force initialize afterwards.
ctrl.ForceInitialize();

By your print screen, it seems that you are docking everyting inside one panel or tab. But that panel is not docked in the Form itself, isn't that the problem?

You should always do :

GridControl1.DockStyle = DockStyle.Fill;

and also dock the container:

Panel1.DockStyle = DockStyle.Fill
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top