Solved

DATAGRIDVIEW INSIDE GROUPBOX

Posted on 2013-06-06
10
1,020 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
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!

 
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

Independent Software Vendors: 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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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