DevExpress VGridControl 行寬自動調整

A5456232發表於2015-08-17

1. 讓列的寬度自動填充

如果VGridControl的LayoutStyle屬性為BandsView或SingleRecordView,那麼把VGridControl的OptionsView.AutoScaleBands設為True就OK了;

如果LayoutStyle屬性為MultiRecordView,那麼就得寫程式碼了,在Form的Load和VGridControl的SizeChanged事件呼叫下面的方法:

private void RecalcWidth() {
    int recordWidth = (vGridControl1.Width - vGridControl1.RowHeaderWidth) / dataTable.Rows.Count;
    if (recordWidth > vGridControl1.RecordMinWidth) {
        vGridControl1.RecordWidth = recordWidth;
        vGridControl1.ScrollVisibility = DevExpress.XtraVerticalGrid.ScrollVisibility.Vertical;
    } else {
        vGridControl1.ScrollVisibility = DevExpress.XtraVerticalGrid.ScrollVisibility.Auto;
    }
}

2.  改vgridcontrol的cell的時候,如果不按回車或者選中另外的cell,它不更改,也就是vgridcontrol沒有失去焦點,所以如果有別的控制元件有滑鼠點選事件,可以先讓這個控制元件獲得焦點,這樣vgridcontrol繫結的資料來源就會更新。

轉載於:https://www.cnblogs.com/chen-whutgis/p/4737154.html

相關文章