zwk333
zwk333
采纳率0%
2015-10-16 01:45 阅读 2.2k

devexpress:画面再次载入后,bandgridview的列宽自动变长

初次进入画面或者关掉画面再打开都是正常, 每列的长度都是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)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • zwk333 zwk333 2015-10-26 05:46

    好久才发现,还有个帖子没人回答。
    现在自行解决了,如果是要bandview的方式来展现图片中效果,可以用下列方式来实现:
    第1列
    GridBand mainBand = new GridBand();
    第2列
    GridBand subMainband = new GridBand();
    要实现band2列的效果,可参考下行代码
    mainBand.Children.Add(subMainband);
    第3列
    BandedGridColumn subBand = new BandedGridColumn();
    第3列一般是隐藏的,只用于绑定datatable时用。
    this.bandedGridView1.OptionsView.ShowColumnHeaders = false;

    点赞 评论 复制链接分享

相关推荐