|
-
Oct 27th, 2013, 07:20 PM
#1
Thread Starter
Addicted Member
DatagridView column size
Hello, I want to resize some columns on form load programmatically. Here's my code:
Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim resetBtn = New Button With {.Text = "S", .Width = 20}
dtp.Name = "dtp"
dtp.Width = 80
'TODO: This line of code loads data into the 'MakbuzDataSet.makbuzT' table. You can move, or remove it, as needed.
Me.MakbuzTTableAdapter.Fill(Me.MakbuzDataSet.makbuzT)
MakbuzTDataGridView.Dock = DockStyle.Bottom
Me.SavePending = True
AddHandler dtp.ValueChanged, AddressOf DateTimePicker1_ValueChanged
FillByTest08ToolStrip.Items.Add(New ToolStripControlHost(dtp))
FillByTest08ToolStrip.Items.Add(New ToolStripControlHost(resetBtn))
Button1.Visible = False
FillByTest08ToolStrip.Margin = New Padding(150, 150, 150, 150)
FillByTest08ToolStrip.Dock = DockStyle.Top
MakbuzTDataGridView.Dock = DockStyle.Fill
MakbuzTDataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
MakbuzTDataGridView.ColumnHeadersHeight = 75
MakbuzTDataGridView.EnableHeadersVisualStyles = True
AddHandler resetBtn.Click, AddressOf onresetBtnClick
MakbuzTDataGridView.CurrentCell = MakbuzTDataGridView(0, 0)
MakbuzTDataGridView.TabIndex = 0
MakbuzVars = Utils.Load(Of Info)("ayarlar.xml")
MakbuzTDataGridView.Columns(1).Width = 150
End Sub
I'm using Visual Studio 2012. How can I resize a column?
-
Oct 27th, 2013, 07:39 PM
#2
Re: DatagridView column size
Code:
DataGridView1.Columns(columnIndex).Width = 100
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 27th, 2013, 07:40 PM
#3
Re: DatagridView column size
seems you've already found how???:
Code:
MakbuzTDataGridView.Columns(1).Width = 150
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 27th, 2013, 07:41 PM
#4
Thread Starter
Addicted Member
Re: DatagridView column size
Thanks for the reply. Yes, I tried it, it doesn't work.
-
Oct 27th, 2013, 07:48 PM
#5
Re: DatagridView column size
in the first line of Form1_Load, put Stop.
then run the code, when it stops, step through the code (F11)
are there any unexpected problems?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 27th, 2013, 07:52 PM
#6
Thread Starter
Addicted Member
Re: DatagridView column size
no, there isn't any problems
-
Oct 27th, 2013, 07:56 PM
#7
Thread Starter
Addicted Member
Re: DatagridView column size
But I'm getting a warning:

Uploaded with ImageShack.us
at this line: Me.MakbuzTTableAdapter.Fill(Me.MakbuzDataSet.makbuzT)
-
Oct 27th, 2013, 08:02 PM
#8
Re: DatagridView column size
just click yes on the dialog.
after:
Code:
MakbuzTDataGridView.Columns(1).Width = 150
put:
Code:
MsgBox(MakbuzTDataGridView.Columns(1).Width)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 27th, 2013, 08:03 PM
#9
Thread Starter
Addicted Member
Re: DatagridView column size
it shows 150
-
Oct 27th, 2013, 08:06 PM
#10
Re: DatagridView column size
the DataGridViewColumn has 2 properties that would affect this... Resizable + AutoSizeMode
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 27th, 2013, 08:10 PM
#11
Thread Starter
Addicted Member
Re: DatagridView column size
I tried:
Code:
MakbuzTDataGridView.Columns(1).Resizable = False
MakbuzTDataGridView.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
MakbuzTDataGridView.Columns(1).Width = 150
Same thing
-
Oct 27th, 2013, 08:15 PM
#12
Re: DatagridView column size
I can't recreate your problem, so there's nothing more I can think of to suggest...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 27th, 2013, 08:16 PM
#13
Thread Starter
Addicted Member
Re: DatagridView column size
-
Oct 27th, 2013, 08:19 PM
#14
Re: DatagridView column size
are you sure that the column you're expecting to be at index 1 is in fact index 1?
if you have any hidden columns or reordered columns, you could be looking at the wrong column
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 27th, 2013, 08:23 PM
#15
Thread Starter
Addicted Member
Re: DatagridView column size
just a stupid mistake. thanks a lot.
-
Oct 27th, 2013, 08:25 PM
#16
Re: DatagridView column size
last guess - I think you'll probably find you need to adjust the column width after setting your datasource
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|