更改网格视图列的大小 [英] change grid view columns size

查看:81
本文介绍了更改网格视图列的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了c#窗口应用程序,并且具有数据网格.
在数据网格中,我有3列,我想像这样更改列的大小:
第一栏是没有.所以我希望第二个时间要小一些,所以这将比第一列大,并且要使第3列大然后全部.
我将数据添加到带有数据表的数据网格中.

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;


但出现以下错误:

索引超出范围.必须为非负数并且小于集合的大小.
参数名称:index


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

推荐答案

首先清除您的问题.您要说的是正在创建Windows应用程序,因此它不是网格视图,而是DataGridView控件.您可以将AutoSizeMode属性设置为None,将Resizable属性设置为False,将ReadOnly属性设置为true,并将Width属性设置为适当的值. 或者您可以将AutoSizeMode属性设置为基于内容的调整大小模式.

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

如果希望将其用于Asp网格视图,则可以使用Grid View的ItemStyle属性.
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.
GridView1.Columns[i].ItemStyle.Width = colWidth;


引用该线程
http://stackoverflow.com/questions/3820245/resizing-datagridview- column-based-on-the-grid-width [ ^ ]
也请阅读这篇文章
具有持久列宽和顺序的DataGridView [
Refer this thread
http://stackoverflow.com/questions/3820245/resizing-datagridview-columns-based-on-the-grid-width[^]
Read this article too
DataGridView with Persistent Column Widths and Order[^]


检查此博客
http://msdn.microsoft.com/en-us/library/ms178296.aspx [ ^ ]
--NDK
check this blog
http://msdn.microsoft.com/en-us/library/ms178296.aspx[^]
--NDK


这篇关于更改网格视图列的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆