How To Change Size Of Datagridview In C#
-
December 21st, 2019,03:05 AM #i
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
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
ThanksI don't program, I crush code into submission!!!
-
December 21st, 2019,03:10 AM #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.
-
Dec 27th, 2019,02:eighteen PM #3
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
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
Thanks again for your assistance. (Below is a screenshot of how I gear up the trackbars. )
I don't program, I shell code into submission!!!
-
Dec 27th, 2019,02:19 PM #4
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
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
Thanks again for your help. (Below is a screenshot of how I ready the trackbars. )
Last edited by vbcub; December 27th, 2019 at 02:25 PM.
I don't plan, I beat code into submission!!!
-
Dec 31st, 2019,12:49 AM #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
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:
- Coding Examples:
-
December 31st, 2019,12:51 AM #6
Re: Change the width of a datagridview at runtime
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
- Coding Examples:
-
Dec 31st, 2019,03:20 AM #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:
- Coding Examples:
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