Solved

DATAGRIDVIEW INSIDE GROUPBOX

Posted on 2013-06-06
10
955 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
-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
Comment Utility
can u post screenshot of how it looks like with your code?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
Please see it.

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

Expert Comment

by:sedgwick
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ok.

Thank you very much for your help.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now