初次进入画面或者关掉画面再打开都是正常, 每列的长度都是100. 如果按下test按钮刷新,列宽自动变长,超过100. 求助各位大侠。
![private void Form1_Load(object sender, EventArgs e)
{
GridBand band1 = new GridBand();
band1.Caption = "band1";
this.bandedGridView1.Bands.Add(band1);
GridBand band2 = new GridBand();
band2.Caption = "band2";
this.bandedGridView1.Bands.Add(band2);
GridBand mainBand = new GridBand();
BandedGridColumn subBand = new BandedGridColumn();
for (int i = 0; i < this.bandedGridView1.Bands.Count; i++)
{
mainBand = this.bandedGridView1.Bands[i];
if (i < 1)
{
subBand = new BandedGridColumn();
subBand.Name = "col" + i;
subBand.Caption = "colName" + i;
subBand.FieldName = "col" + i;
subBand.Width = 100;
subBand.Visible = true;
mainBand.Columns.Add(subBand);
}
else
{
for (int m = 0; m < 4; m++)
{
subBand = new BandedGridColumn();
subBand.Name = "col" + m;
subBand.Caption = "colName" + m;
subBand.FieldName = "col" + m;
subBand.Width = 100;
subBand.Visible = true;
mainBand.Columns.Add(subBand);
}
}
}
}
private void btnTest_Click(object sender, EventArgs e)
{
this.bandedGridView1.Bands.Clear();
this.bandedGridView1.Columns.Clear();
Form1_Load(sender, e);
}
}
图片说明](https://img-ask.csdn.net/upload/201510/16/1444959958_310970.jpg)