Click here to Skip to main content
14,735,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi How can i change datagridview columns AUTOFİT and same time MANUEL control

i use this code but columns locking

What I have tried:

STOK_TABLO.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
Posted
Updated 4-Sep-20 22:45pm
Comments
Sandeep Mewara 5-Sep-20 3:36am
   
It's not clear on what you are trying. Maybe if you explain more of the scenario you have that you are trying to implement.

1 solution

You can't use a manual width and autofit on the same column: autofit automatically resizes the column to fit the data.
Autosize will override any width you try to set.

Quote:
OKFirst option is : DGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
Second Option is :.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None

so i want use first and second options both,

when i open form i will see datargridview columns are autofit,

But same time, i should change columns width manuel,


That's a problem: What you are asking for is that the DGV initially fits all the data, but that the columns can later be resized.
You could wait for it to be completely shown, then change the AutoSizeColumnsMode to DataGridViewAutoSizeColumnsMode.None
But ... that will "undo" the widths for all columns, so you'd have to get them first, change the option, then set them back:
Dim cols As List(Of Integer) = New List(Of Integer)()
For Each col As DataGridViewColumn In myDataGridView.Columns
    cols.Add(col.Width)
Next
myDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
Dim i As Integer = 0
For Each col As DataGridViewColumn In myDataGridView.Columns
    col.Width = cols(i)
    i = i + 1
Next
   
v2
Comments
Member 14588284 5-Sep-20 3:50am
   
Do you have any suggestions
OriginalGriff 5-Sep-20 4:23am
   
Loads.
Is there any particular subject you would like a suggestion on?


Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So if there is something specific you want to happen, you have to explain to us exactly what that is: we really don't like guessing! :laugh:
Member 14588284 5-Sep-20 4:29am
   
i wrote what my want
i think its simple and straightforward question
i want autofit size and manuel size control for datagridview columns?
OriginalGriff 5-Sep-20 4:56am
   
But what does that mean?
If a column is autofit you are saying "I want you to control the width of this column so all it's data is always visible"
If you manually set a column to a specific width, you are saying "I want this column to be X pixels wide, regardless of how much data that cuts off".

The two options are mutually exclusive, and we have no idea how you want your DGV to look - so you need to spell it out pretty exactly before we can understand you!
Member 14588284 5-Sep-20 5:18am
   
OKFirst option is : DGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
Second Option is :.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None

so i want use first and second options both,

when i open form i will see datargridview columns are autofit,

But same time, i should change columns width manuel,
(on column header)
(https://docs.telerik.com/devtools/winforms/controls/gridview/columns/resizing-columns-programatically) in this link first shortvide
OriginalGriff 5-Sep-20 5:43am
   
Answer updated
Member 14588284 5-Sep-20 5:49am
   
Thanks Thanks
That's it :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900