Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1134
  • Last Modified:

DATAGRIDVIEW INSIDE GROUPBOX

Hi All,

I have windows form.

I create groupbox and datagridview inside that groupbox at run time.

The problem are :

1. the datagridview size exceed the groupbox.
2. the datagridview has no scroll both horizontal and vertical.

Here is the function to put dgv to groupbox:

 Public Shared Function Add_New_Datagridview_Inside_GroupBox(ByVal gb As GroupBox, _
                                                                ByRef dgv As DataGridView) As DataGridView

        Dim LocX As Integer = 10
        Dim LocY As Integer = 20
        Dim SizeX As Integer = gb.Width - 20
        Dim SizeY As Integer = gb.Height - 30

        With dgv
            .BackgroundColor = Color.White
            .AutoGenerateColumns = True
            .AutoSize = True
            .Size = New Size(SizeX, SizeY)
            .Location = New Point(LocX, LocY)
        End With

        gb.Controls.Add(dgv)

        Return dgv

    End Function

public class Form1

            Private dgvJenis As DataGridView

            at form load
              dgvJenis = Screen_Function.Add_New_Datagridview_Inside_GroupBox(gb, dgvJenis)

End Class

What is wrong ?

Thank you.
0
emi_sastra
Asked:
emi_sastra
  • 5
  • 5
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
after this line:  gb.Controls.Add(dgv)

add this:
dgv.Dock = DockStyle.Fill
dgv.ScrollBars = ScrollBars.Both

Open in new window

0
 
emi_sastraAuthor Commented:
Hi sedgwick,

It works.

Why we need :

dgv.Dock = DockStyle.Fill

What wrong with :

   .Size = New Size(SizeX, SizeY)
            .Location = New Point(LocX, LocY)

Thank you.
0
 
Meir RivkinFull stack Software EngineerCommented:
setting DockStyle.Fill always re-position the dgv to the groupbox edges whenever the groupbox size changes.
so u don't have to handle any event to accomplish that, the control re-position it self.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
emi_sastraAuthor Commented:
-setting DockStyle.Fill always re-position the dgv to the groupbox edges whenever the groupbox size changes.
Yes, I know. I just curious what's wrong with my code.

Thank you.
0
 
Meir RivkinFull stack Software EngineerCommented:
can u post screenshot of how it looks like with your code?
0
 
emi_sastraAuthor Commented:
Please see it.

Thank you.
SCREEN-SHOT-DGV-INSIDE-GROUPBOX.PNG
0
 
Meir RivkinFull stack Software EngineerCommented:
it seems that u didn't use relative coordinates, but i need to debug your code to check the coordinates and location of each control.
0
 
emi_sastraAuthor Commented:
Please see below code :


            Dim gb As GroupBox = Screen_Function.Add_New_Group_Box(flpData, "grbJenis", "Jenis Barang", intGroupBoxWidth, intGroupBoxHeight)

            dgvJenis = Screen_Function.Add_New_Datagridview_Inside_GroupBox(gb)


    Public Shared Function Add_New_Group_Box(parentControl As Control, _
                                             strName As String, _
                                             strText As String, _
                                             intWidth As Integer, _
                                             intHeight As Integer) As GroupBox
        Dim gb As New GroupBox

        With gb
            '.BackColor = Color.Black
            '.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
            .Name = strName
            .Text = strText
            .Size = New Size(intWidth, intHeight)
            .ForeColor = Color.Blue
        End With

        parentControl.Controls.Add(gb)

        Return gb

    End Function

Is something wrong with the above code ?

Thank you.
0
 
Meir RivkinFull stack Software EngineerCommented:
i've no way to know, i need to debug the code and check the coordinates. sorry
0
 
emi_sastraAuthor Commented:
Ok.

Thank you very much for your help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now