banner



How To Change Size Of Datagridview In C#

  1. #i

    vbcub is offline

    Thread Starter

    Lively Member


    Alter the width of a datagridview at runtime

    I have a laptop with a 14 inch screen. I am trying to change the width of a datagridview to fit the width of the grade it is in. I set the width of my form in the form load:

    Code:

                              Me.Location = New Point(0, 65)         Me.Width = 1560         Me.Meridian = 728
    I as well bear witness the size of the form in the text header so I can see what the the size of the form is so I can grab the handles of the form and motility til I get the size that I want and and then change the code accordingly.

    Code:

    Private Sub Score_Update_LocationChanged(sender As Object, e As EventArgs) Handles Me.LocationChanged         Dim CurrentXX As Integer = Me.Left         Dim Currentyy As Integer = Me.Height         Dim Currentww As Integer = Me.Width         Dim Currenthh As Integer = Me.Height         Me.Text = "Spots to be picked: X = " & CurrentXX & "Y = " & Currentyy & " Width: " & Currentww & " Tiptop: " & Currenthh     End Sub
    When I modify the width of my datagrdview in the datagridview backdrop to correspond to the width of the form, it doesn't lucifer the width of the form. What I would like to practice is to change 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 accept tried to google changing the width of the datagridview, merely it comes back to changing a column width of a cavalcade. What am I doing wrong?
    Thanks

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


  2. #ii

    Re: Change the width of a datagridview at runtime

    You should exist using the Anchor holding so that the grid resizes automatically when the form resizes. I suggest that you follow the CodeBank link in my signature beneath and cheque out my thread on the Anchor & Dock properties.

  3. #3

    vbcub is offline

    Thread Starter

    Lively Member


    Re: Modify the width of a datagridview at runtime

    Thanks for your reply. I wrote my question at two:00 am and was non as clear as I should have been. What I was looking for was a way to expand and/or contract a datagridview at runtime then I could get the exact size that I wanted. I wanted to know if controls had resize handles similar forms practise. Evidently not. The solution (for my needs) is to use trackbars. I set the size of the datagridview to what I call back it will be in the grade load sub forth with minimums and maximums similar so:

    Code:

                              Private Sub Form1_Load(sender As Object, e Equally 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 the post-obit subs to alter the meridian and width using the trackbars:

    Code:

                              Private Sub Label2_TextChanged(sender Every bit Object, e As EventArgs) Handles Label2.TextChanged         DataGridView1.Elevation = Val(Label2.Text)     Stop Sub     Private Sub Label3_TextChanged(sender Equally Object, eastward As EventArgs) Handles Label3.TextChanged         DataGridView1.Width = Val(Label3.Text)     End Sub      Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll         Label2.Text = TrackBar1.Value     Stop 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 will until I get the exact size of datagridview that I desire. Then I either change the sizes in the form load or belongings list of the control. I really wasn't looking for a way to resize the datagridview as I was resizing the grade. I apologize for non asking the question properly.

    Thanks again for your assistance. (Below is a screenshot of how I gear up the trackbars. )

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

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


  4. #4

    vbcub is offline

    Thread Starter

    Lively Member


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

    Cheers for your answer. I wrote my question at 2:00 am and was non as clear equally I should take been. What I was looking for was a manner to expand and/or contract a datagridview at runtime so I could get the exact size that I wanted. I wanted to know if controls had resize handles similar forms exercise. Evidently not. The solution (for my needs) is to use trackbars. I set the size of the datagridview to what I call back information technology volition be in the form load sub forth with minimums and maximums like and then:

    Code:

                              Private Sub Form1_Load(sender Equally Object, eastward 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.Height         TrackBar2.Maximum = 1200         TrackBar2.Value = Me.DataGridView1.Height         End sub
    And so I add the following subs to change the height and width using the trackbars:

    Code:

                              Private Sub Label2_TextChanged(sender Every bit Object, e As EventArgs) Handles Label2.TextChanged         DataGridView1.Height = Val(Label2.Text)     End Sub     Individual Sub Label3_TextChanged(sender As Object, e As EventArgs) Handles Label3.TextChanged         DataGridView1.Width = Val(Label3.Text)     End Sub      Private Sub TrackBar1_Scroll(sender As Object, east As EventArgs) Handles TrackBar1.Ringlet         Label2.Text = TrackBar1.Value     End Sub     Individual Sub TrackBar2_Scroll(sender Equally Object, eastward Every bit EventArgs) Handles TrackBar2.Coil         Label3.Text = TrackBar2.Value     End Sub
    and I can change the width and top at will until I get the exact size of datagridview that I want. Then I either change the sizes in the form load or property listing of the control. I really wasn't looking for a mode to resize the datagridview as I was resizing the grade. I repent for not request the question properly.

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

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

    Last edited by vbcub; December 27th, 2019 at 02:25 PM.

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


  5. #5

    Re: Change the width of a datagridview at runtime

    It's a radical solution using trackbars that way. Yous could lose some of this coding...

    Code:

    Private Sub Label2_TextChanged(sender As Object, e Every bit EventArgs) Handles Label2.TextChanged     DataGridView1.Superlative = Val(Label2.Text) End Sub Individual Sub Label3_TextChanged(sender As Object, due east As EventArgs) Handles Label3.TextChanged     DataGridView1.Width = Val(Label3.Text) End Sub  Private Sub TrackBar1_Scroll(sender Equally Object, e As EventArgs) Handles TrackBar1.Whorl     Label2.Text = TrackBar1.Value Finish Sub Individual Sub TrackBar2_Scroll(sender As Object, due east As EventArgs) Handles TrackBar2.Whorl     Label3.Text = TrackBar2.Value Terminate Sub
    Why convert the value to a String (in the Label.Text), so catch the TextChanged and convert information technology to a double?

    Code:

    Private Sub TrackBar1_Scroll(sender Every bit Object, e Equally EventArgs) Handles TrackBar1.Whorl     Label2.Text = TrackBar1.Value     DataGridView1.Tiptop = TrackBar1.Value End Sub Individual Sub TrackBar2_Scroll(sender As Object, e As EventArgs) Handles TrackBar2.Curlicue     Label3.Text = TrackBar2.Value     DataGridView1.Width = TrackBar2.Value Cease Sub


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



  6. #6

    Re: Change the width of a datagridview at runtime



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



  7. #seven

    Re: Change the width of a datagridview at runtime

    To be honest, you need to do the calculations behind the scenes for the type of application you're developing...


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



How To Change Size Of Datagridview In C#,

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

Posted by: redfieldfoublinges.blogspot.com

0 Response to "How To Change Size Of Datagridview In C#"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel