Click here to Skip to main content
15,443,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I develop c# window application and i have data grid.
In data grid i have 3 columns i want to change columns size like this:
First column is no. so i want it small second is time so this will bigger than first column and want to make 3 column bigger then all.

i add data in data grid with data table.

private void createtable()
       {
           dt = new DataTable();
           dt.Columns.Add("Frame");
           dt.Columns.Add("Time");
           dt.Columns.Add("Data");
       }


I want to change size of Frame,Time and Data i want different size as i told above.
Please solve this.
i use this code:
grid1.Columns[0].Width = 50;

but i got following error:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Posted
Updated 6-Dec-11 1:22am
v4

First of all clear your question.You are saying your are creating windows application so it's not grid view it's DataGridView Control.You can Set the AutoSizeMode property to None, the Resizable property to False, the ReadOnly property to true, and the Width property to an appropriate value.
or you can Set the AutoSizeMode property to a content-based sizing mode.

See : http://msdn.microsoft.com/en-us/library/fd004dhd.aspx[^]

If you want it for Asp grid view You can use the ItemStyle Property of Grid View.
C#
GridView1.Columns[i].ItemStyle.Width = colWidth;
 
Share this answer
 
Comments
NandaKumer 14-Dec-11 16:14pm    
nice one.
 
Share this answer
 
v2
Comments
NandaKumer 14-Dec-11 16:13pm    
nice link
 
Share this answer
 
By setting-

C#
dataGridView1.Columns[0].Width = 50;

then check by executing whether size perfect or not according change value(number).
 
Share this answer
 
v2
Comments
jaideepsinh 5-Dec-11 6:19am     CRLF
If i use this code i got error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
C#
grid1.Columns[0].Width = 150;
grid1.Columns[1].Width = 150;
 
Share this answer
 
v2
Comments
RaisKazi 14-Dec-11 10:23am    
Edited: Added "pre" tag.

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