Solved

DATAGRIDVIEW INSIDE GROUPBOX

Posted on 2013-06-06
10
1,067 Views
Last Modified: 2013-06-06
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
Comment
Question by:emi_sastra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39225430
after this line:  gb.Controls.Add(dgv)

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

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39225642
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
 
LVL 42

Expert Comment

by:sedgwick
ID: 39225660
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 1

Author Comment

by:emi_sastra
ID: 39225682
-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
 
LVL 42

Expert Comment

by:sedgwick
ID: 39225739
can u post screenshot of how it looks like with your code?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39225790
Please see it.

Thank you.
SCREEN-SHOT-DGV-INSIDE-GROUPBOX.PNG
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39225982
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
 
LVL 1

Author Comment

by:emi_sastra
ID: 39226017
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
 
LVL 42

Expert Comment

by:sedgwick
ID: 39226062
i've no way to know, i need to debug the code and check the coordinates. sorry
0
 
LVL 1

Author Closing Comment

by:emi_sastra
ID: 39226128
Ok.

Thank you very much for your help.
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question