Results 1 to 6 of 6

Thread: DataGrid and MDIForm

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2017
    Posts
    19

    DataGrid and MDIForm

    How to customize a datagrid to MDIForm resolution


    MDIForm1.zip

  2. #2
    gibra
    Guest

    Re: DataGrid and MDIForm

    What you want to do, exactly?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2017
    Posts
    19

    Re: DataGrid and MDIForm

    I would like the datagrid to auto-fit to MDIForm

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: DataGrid and MDIForm

    I assume you have a datagrid control in a form which is a mdichild?

    The most simple thing would be:
    Code:
    Private Sub Form_Resize()
    
      If Me.WindowState <> vbMinimized Then
        DataGrid1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
      End If
    
    End Sub

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: DataGrid and MDIForm

    You can't do what you want if the datagrid is placed on the MDI parent. If you could, then you would not have any client area on the MDI to display any child forms. The MDI client area is subtracted from the space used by sited controls. And since you expect the grid to fill the client area, the available space for MDI child forms is zero.

    Here's a suggestion:
    1. Create a borderless form, as a MDI child. We'll call that form: frmDataGrid
    2. Place your ADODC and Datagrid onto that child form. Set the Align property of the controls as needed
    3. In the MDIForm_Load event, add this: frmDataGrid.Show
    4. In the MDIForm_Resize event, add this
    Code:
    On Error Resume Next
        With frmDataGrid
            .Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
        End With
    5. In the frmDataGrid form's Form_Resize event, add this
    Code:
        On Error Resume Next
        With DataGrid1
            .Move .Left, .Top, Me.ScaleWidth, Me.ScaleHeight - .Top
        End With
    What the above does is use a borderless MDI Child form that is initially loaded in the MDI parent. When the MDI parent resizes, it resizes the child form. When the child form resizes, it resizes the datagrid. Since the child is borderless, it can't easily be closed. And any subsequent child forms will not be placed behind frmDataGrid.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    Hyperactive Member
    Join Date
    Feb 2014
    Posts
    278

    Re: DataGrid and MDIForm

    Quote Originally Posted by ewcia87 View Post
    How to customize a datagrid to MDIForm resolution
    Quote Originally Posted by ewcia87 View Post
    I would like the datagrid to auto-fit to MDIForm
    Do you want to auto-size the DataGrid columns to fill the width of the MDIForm width? If this is what you want, it still will not look nice because there are only 3 columns and they will look stretched. Maybe put them on the left instead. Picturebox align left and the adodc1 and DataGrid1 inside Picturebox. You size them to fit.
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width