加上这句:
dataGrid.Style["TABLE-LAYOUT"] = "fixed"
dataGrid.Style["TABLE-LAYOUT"] = "fixed"
解决方案 »
- winform CheckBoxList 判断选择项
- 谁熟悉php的正则,请帮转成C#的
- vs 打包的问题。麻烦高手解决下。
- 怎样去除DateEdit和ComboBox中的黑色边框
- 二个列表框(listBox)左右数据传输问题
- 有人知道List<>什么意识吗?
- VS2005如何给C#做一个Project Template?高手指路啊!
- 主机A使用UdpClient的Receive()向内网主机B发送消息,主机B收到消息后发送应答消息到主机A,主机A为什么收不到应答?
- 用接口好还是抽象类好? 请高人进来分析一下
- 如何用C#实现带链接的网页?
- 如何用c#做mp3播放程序
- 在DATAGRID的父子关系表中怎样禁止子表的新增行?
第二种。在DATAGRID的SETDATABINGDING之前加入下面的代码://STEP 1: Create a DataTable style object and set properties if required.
DataGridTableStyle ts1 = new DataGridTableStyle(); //specify the table from dataset (required step)
ts1.MappingName = "EastCoastSales";
// Set other properties (optional step)
ts1.AlternatingBackColor = Color.LightBlue; //STEP 2: Create a string column and add it to the tablestyle
DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "custName"; //from dataset table
TextCol.HeaderText = "Customer Name";
TextCol.Width = 100;
ts1.GridColumnStyles.Add(TextCol); //STEP 3: Create an int column style and add it to the tablestyle
//this requires setting the format for the column through its property descriptor
PropertyDescriptorCollection pdc = this.BindingContext
[myDataSet, "EastCoastSales"].GetItemProperties(); //now created a formated column using the pdc
DataGridTextBoxColumn csIDInt =
new DataGridTextBoxColumn(pdc["CustID"], "i", true);
csIDInt.MappingName = "CustID";
csIDInt.HeaderText = "CustID";
csIDInt.Width = 50;
ts1.GridColumnStyles.Add(csIDInt); //STEP 4: Add the checkbox
DataGridColumnStyle boolCol = new DataGridBoolColumn();
boolCol.MappingName = "Current";
boolCol.HeaderText = "Info Current";
boolCol.Width = 70;
ts1.GridColumnStyles.Add(boolCol);
//STEP 5: Add the tablestyle to your datagrid抯 tablestlye collection
myDataGrid.TableStyles.Add(ts1);