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
Solved

DATAGRIDVIEW INSIDE GROUPBOX

Posted on 2013-06-06
10
1,003 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I need help making a collection from a class in VB.Net 3 42
Variable Event ? 3 36
get column names from table in vb.net 8 49
vb.net class 3 21
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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