摘要:dxGrid 相關操作
Layout 存取
gridView1.SaveLayoutToXml("C:/b.xml");
gridView1.RestoreLayoutFromXml("C:/b.xml");
資料綁定
//先停止Event 發生
this.gridView1.ColumnFilterChanged -= new System.EventHandler(this.gridView1_ColumnFilterChanged);
//取回DataSource資料
WebServiceEncodeLib ws = new WebServiceEncodeLib();
DataSet ds = ws.getDataSetXml(SQL);
//給定DataSource , 如果沒有先停止event , 在給定DataSource 同時會觸發 ColumnFilterChanged
gridControl1.DataSource = ds.Tables[0];
//設定顯示
gridView1.BestFitColumns();
gridView1.Columns["QTY"].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
gridView1.Columns["GW"].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
//再啟動 event
this.gridView1.ColumnFilterChanged += new System.EventHandler(this.gridView1_ColumnFilterChanged);
塗色和粗體
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.Column.FieldName == "TUB")
{
if (Convert.ToInt32( e.DisplayText) < 5)
{
e.Appearance.ForeColor = Color.Red;
e.Appearance.Font = new Font(e.Appearance.Font, FontStyle.Bold);
}
}
}
取消自動欄位寬
this.gridView1.OptionsView.ColumnAutoWidth = false;
取得點選資料
string KEY_WORD = gridView1.GetDataRow(gridView1.FocusedRowHandle)["bullet_no"].ToString();
((DevExpress.XtraGrid.Views.Grid.GridView)sender).GetDataRow(e.RowHandle)["xxx"].ToString();