如何调整datagridwiew列的大小 [英] how to re size datagridwiew column

查看:65
本文介绍了如何调整datagridwiew列的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DataTable Stb = new DataTable("SearchTB");
            Stb.Columns.Add("SCode", typeof(string));
            Stb.Columns.Add("SName", typeof(string));
            OdbcCommand cmd = new OdbcCommand("SELECT  ItemCode, Description FROM ITEM", MainClass.Conn);
            OdbcDataAdapter da = new OdbcDataAdapter(cmd);
            da.Fill(Stb);
            da.Dispose();
            gvSearch.DataSource = Stb;


执行上述代码后,它会生成两个空白列,我想将记录(ItemCode/Description)添加到预定义列(SCode/SName),并希望重新调整数据网格视图列的宽度


after executing the above code it''s generate two blank columns i want to add records(ItemCode/Description) to predefined columns(SCode/SName) And Want To re size the data grid view columns width

how to do this..?

推荐答案

您可以使用网格视图的行数据绑定事件来调整列宽的大小. 使用以下代码:

you can use row data bound event of grid view to re-size column width.
use following code :

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
(
   if (e.Row.RowType == DataControlRowType.Header)
   {
       e.Row.Cells[1].Width = 100;
       e.Row.Cells[2].Width = 100;
   }
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
       e.Row.Cells[1].Width = 100;
       e.Row.Cells[2].Width = 100;
   }
}


这篇关于如何调整datagridwiew列的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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