Results 1 to 3 of 3

Thread: [RESOLVED] Binded DataGridView in Another Form

  1. #1

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Resolved [RESOLVED] Binded DataGridView in Another Form

    Hi

    I have a "little" form that has 5 datagridview's, so it's a little full, sometimes some of the dgvs have a lot of rows, so it's a little annoying trying to edit the data.
    So I was thinking in someway to solve this situation, and i thought in a new form that pop ups when the user select the datagridview...
    Something like, event, save the position, save the size, remove from the original form, opens a new form, add the dgv and set the docking to full... The user edits everything and when closing the form, i just remove the dock, and set the position and the original size...

    It's possible? without a large amount of work..

    The events and the bindings columns that are in the original form, what will happen? Maybe i should try with a sample project...
    Anyway meanwhile i accept suggestions.

    Thanks

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: Binded DataGridView in Another Form

    I don't know exactly what your form design looks like but might it be easier to use a TabControl so that only one grid is visible at a time? TabControls exist to reduce clutter on forms with lots of controls.

    If that's not appropriate then you certainly can do what you suggest. It's a simple matter of Adding the control to the Controls collection of the other form. If it's not docked then you'll have to adjust the Location and Size as required as well. The object will still be assigned to the same member variable in the original form so you can still reference it and handle its events in the same way you always did. When you're done you simply Add it back to the Controls collection of the original form. You should try it with a simple test project first.

  3. #3

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Binded DataGridView in Another Form

    Thanks JMC
    The tabs aren't an option in this form.
    But after posting here, i made some tests and everything works fine... It was simpler that i thought.

    Here's the sample code:
    vb.net Code:
    1. Private Sub DataGridView1_Click(sender As Object, e As System.EventArgs) Handles DataGridView1.Click
    2.         If DataGridView1.Parent.Name = "FormEdit" Then Exit Sub
    3.         Dim newEdit As New FormEdit
    4.         Dim currentDGV As DataGridView = Me.DataGridView1
    5.         Dim pos As Point = currentDGV.Location
    6.         Dim size As Size = currentDGV.Size
    7.  
    8.         'Remove
    9.         Me.Controls.Remove(currentDGV)
    10.  
    11.         'Add
    12.         With currentDGV
    13.             .Dock = DockStyle.Fill
    14.         End With
    15.         newEdit.Controls.Add(currentDGV)
    16.         newEdit.TopMost = True
    17.         newEdit.ShowDialog()
    18.  
    19.         'Restore
    20.         newEdit.Controls.Remove(currentDGV)
    21.         With currentDGV
    22.             .Dock = DockStyle.None
    23.             .Size = size
    24.             .Location = pos
    25.         End With
    26.  
    27.         Me.Controls.Add(currentDGV)
    28.  
    29.     End Sub

    Rate People That Helped You
    Mark Thread Resolved When Resolved

Tags for this Thread

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