banner



How To Change Size Of Datagridview With Window Inn C#

  1. #1

    vbcub is offline

    Thread Starter

    Lively Member


    Change the width of a datagridview at runtime

    I accept a laptop with a xiv inch screen. I am trying to modify the width of a datagridview to fit the width of the form it is in. I fix the width of my form in the form load:

    Code:

                              Me.Location = New Betoken(0, 65)         Me.Width = 1560         Me.Height = 728
    I too evidence the size of the form in the text header so I can encounter what the the size of the grade is so I can grab the handles of the form and move til I become the size that I desire and so alter the lawmaking accordingly.

    Code:

    Private Sub Score_Update_LocationChanged(sender Equally Object, due east As EventArgs) Handles Me.LocationChanged         Dim CurrentXX As Integer = Me.Left         Dim Currentyy Every bit Integer = Me.Top         Dim Currentww As Integer = Me.Width         Dim Currenthh As Integer = Me.Height         Me.Text = "Spots to be picked: X = " & CurrentXX & "Y = " & Currentyy & " Width: " & Currentww & " Height: " & Currenthh     End Sub
    When I alter the width of my datagrdview in the datagridview properties to correspond to the width of the form, it doesn't match the width of the form. What I would similar to practice is to modify the width of the datagridview at runtime so I can see what size information technology is and change the width of the control to better fit the form. I have tried to google changing the width of the datagridview, but it comes back to changing a column width of a column. What am I doing wrong?
    Thanks

    I don't program, I beat code into submission!!!


  2. #2

    Re: Change the width of a datagridview at runtime

    You lot should be using the Anchor belongings so that the filigree resizes automatically when the form resizes. I suggest that you follow the CodeBank link in my signature below and check out my thread on the Anchor & Dock properties.

  3. #3

    vbcub is offline

    Thread Starter

    Lively Fellow member


    Re: Change the width of a datagridview at runtime

    Thanks for your reply. I wrote my question at 2:00 am and was not as clear as I should have been. What I was looking for was a way to aggrandize and/or contract a datagridview at runtime and so I could get the exact size that I wanted. I wanted to know if controls had resize handles like forms practice. Evidently not. The solution (for my needs) is to utilize trackbars. I set the size of the datagridview to what I think information technology volition exist in the form load sub along with minimums and maximums like so:

    Code:

                              Private Sub Form1_Load(sender Every bit Object, due east As EventArgs) Handles MyBase.Load         Label2.Text = 250         Label3.Text = 500         TrackBar1.Minimum = 250         TrackBar1.Maximum = 1500         TrackBar1.Value = 250         TrackBar2.Minimum = 500         TrackBar2.Maximum = 1200         TrackBar2.Value = 500         End sub
    Then I add together the following subs to change the pinnacle and width using the trackbars:

    Code:

                              Private Sub Label2_TextChanged(sender Equally Object, e As EventArgs) Handles Label2.TextChanged         DataGridView1.Height = Val(Label2.Text)     End Sub     Private Sub Label3_TextChanged(sender As Object, e Every bit EventArgs) Handles Label3.TextChanged         DataGridView1.Width = Val(Label3.Text)     Finish Sub      Private Sub TrackBar1_Scroll(sender As Object, eastward Equally EventArgs) Handles TrackBar1.Gyre         Label2.Text = TrackBar1.Value     End Sub     Private Sub TrackBar2_Scroll(sender Equally Object, east As EventArgs) Handles TrackBar2.Scroll         Label3.Text = TrackBar2.Value     Stop Sub
    and I can change the width and height at will until I get the verbal size of datagridview that I desire. Then I either alter the sizes in the form load or holding list of the control. I really wasn't looking for a way to resize the datagridview as I was resizing the course. I apologize for non asking the question properly.

    Cheers again for your help. (Below is a screenshot of how I fix up the trackbars. )

    Name:  Employee_Datagridview.jpg  Views: 993  Size:  122.6 KB

    I don't plan, I beat code into submission!!!


  4. #4

    vbcub is offline

    Thread Starter

    Lively Member


    Re: Alter the width of a datagridview at runtime ***Resolved***

    Thank you for your reply. I wrote my question at ii:00 am and was not as clear as I should have been. What I was looking for was a way to expand and/or contract a datagridview at runtime so I could go the verbal size that I wanted. I wanted to know if controls had resize handles like forms practice. Evidently not. The solution (for my needs) is to apply trackbars. I set the size of the datagridview to what I recall it will be in the form load sub forth with minimums and maximums similar then:

    Lawmaking:

                              Individual Sub Form1_Load(sender Equally Object, e As EventArgs) Handles MyBase.Load           Me.DataGridView1.Width = 250         Me.DataGridView1.Height = 500          Label2.Text = Me.DataGridView1.Width         Label3.Text = Me.DataGridView1.Height          TrackBar1.Minimum = Me.DataGridView1.Width         TrackBar1.Maximum = 1500         TrackBar1.Value = Me.DataGridView1.Width         TrackBar2.Minimum = Me.DataGridView1.Summit         TrackBar2.Maximum = 1200         TrackBar2.Value = Me.DataGridView1.Acme         End sub
    Then I add the following subs to modify the height and width using the trackbars:

    Code:

                              Private Sub Label2_TextChanged(sender As Object, eastward As EventArgs) Handles Label2.TextChanged         DataGridView1.Height = Val(Label2.Text)     End Sub     Private Sub Label3_TextChanged(sender As Object, e As EventArgs) Handles Label3.TextChanged         DataGridView1.Width = Val(Label3.Text)     End Sub      Private Sub TrackBar1_Scroll(sender Equally Object, east As EventArgs) Handles TrackBar1.Roll         Label2.Text = TrackBar1.Value     Terminate Sub     Individual Sub TrackBar2_Scroll(sender As Object, e As EventArgs) Handles TrackBar2.Scroll         Label3.Text = TrackBar2.Value     End Sub
    and I can change the width and height at volition until I become the exact size of datagridview that I desire. Then I either modify the sizes in the class load or belongings list of the control. I really wasn't looking for a manner to resize the datagridview as I was resizing the form. I apologize for non asking the question properly.

    Cheers again for your help. (Below is a screenshot of how I set the trackbars. )

    Name:  Employee_Datagridview.jpg  Views: 993  Size:  122.6 KB

    Last edited past vbcub; Dec 27th, 2019 at 02:25 PM.

    I don't program, I crush code into submission!!!


  5. #5

    Re: Modify the width of a datagridview at runtime

    Information technology's a radical solution using trackbars that mode. You could lose some of this coding...

    Code:

    Private Sub Label2_TextChanged(sender As Object, eastward As EventArgs) Handles Label2.TextChanged     DataGridView1.Peak = Val(Label2.Text) End Sub Individual Sub Label3_TextChanged(sender As Object, e Equally EventArgs) Handles Label3.TextChanged     DataGridView1.Width = Val(Label3.Text) End Sub  Private Sub TrackBar1_Scroll(sender As Object, eastward As EventArgs) Handles TrackBar1.Scroll     Label2.Text = TrackBar1.Value Cease Sub Individual Sub TrackBar2_Scroll(sender As Object, east As EventArgs) Handles TrackBar2.Coil     Label3.Text = TrackBar2.Value Finish Sub
    Why catechumen the value to a String (in the Label.Text), and so catch the TextChanged and catechumen it to a double?

    Lawmaking:

    Private Sub TrackBar1_Scroll(sender As Object, due east Equally EventArgs) Handles TrackBar1.Scroll     Label2.Text = TrackBar1.Value     DataGridView1.Height = TrackBar1.Value End Sub Private Sub TrackBar2_Scroll(sender As Object, e As EventArgs) Handles TrackBar2.Scroll     Label3.Text = TrackBar2.Value     DataGridView1.Width = TrackBar2.Value End Sub


    • Coding Examples:
    • Features:
    • Online Games:
    • Compiled Games:



  6. #half dozen

    Re: Alter the width of a datagridview at runtime



    • Coding Examples:
    • Features:
    • Online Games:
    • Compiled Games:



  7. #7

    Re: Change the width of a datagridview at runtime

    To be honest, you need to do the calculations backside the scenes for the blazon of application y'all're developing...


    • Coding Examples:
    • Features:
    • Online Games:
    • Compiled Games:



How To Change Size Of Datagridview With Window Inn C#,

Source: https://www.vbforums.com/showthread.php?881921-Change-the-width-of-a-datagridview-at-runtime

Posted by: riversessfull1982.blogspot.com

0 Response to "How To Change Size Of Datagridview With Window Inn C#"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel