DEVEXPRESS gridview手動新增行和刪除行自定義序號、自定義文字
阿新 • • 發佈:2019-01-05
新增行和刪除
#region 事件_新增行按鈕
private void buttonAdd_Click(object sender, EventArgs e)
{
this.gridView1.AddNewRow();
this.gridView1.SetRowCellValue(this.gridView1.FocusedRowHandle, 列名稱1, 0);//列初始值1
this.gridView1.SetRowCellValue(this.gridView1.FocusedRowHandle, 列名稱2, 100);//列初始值2
this.gridView1.FocusedRowHandle--;
}
#endregion
#region 事件_刪除行按鈕
private void buttonDel_Click(object sender, EventArgs e)
{
this.gridView1.DeleteSelectedRows();
}
}
#endregion
自定行序號
實現一下方法 #region 事件_gridView2序號設定/// <summary>
/// 序號設定
/// </summary>
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
e.Info.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
if (e.RowHandle >= 0)
{
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
else if (e.Info.Kind == DevExpress.Utils.Drawing.IndicatorKind.Header)
{
e.Info.DisplayText = "序號";
}
else
{
e.Info.DisplayText = "";
}
}
#endregion
自定義文字
/// <summary>
/// 自定義列顯示
/// </summary>
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
if (e.Column.FieldName == "列名")
{
if (e.Value != null)
{
}
}
}
#endregion
獲取某行某列值
獲取點選的某行某列值
private void advBandedGridView1_MouseDown(object sender, MouseEventArgs e){ //返回資訊關於檢視元素位置的一個特殊的點
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hInfo = advBandedGridView1.CalcHitInfo(new Point(e.X, e.Y));
}