DevExpress中GridControl的屬性設置及動態綁定數據和全選取消全選


View Code
DevExpress中GridControl的屬性設置
1. 隱藏最上面的GroupPanel
gridView1.OptionsView.ShowGroupPanel=false;

2. 得到當前選定記錄某字段的值
sValue=Table.Rows[gridView1.FocusedRowHandle][FieldName].ToString();

3. 數據只讀
gridView1.OptionsBehavior.Editable=false;

4.不顯示MasterDetailView
gridView1.OptionsDetail.EnableMasterViewMode=false;

5.修改最上面的GroupPanel內容
gridView1.GroupPanelText="CSDN";

6.數據綁定:
FieldName --數據庫的字段名稱

7.讀寫拷貝權限設置
ColumnView.Editable
This property returns a value of the ColumnViewOptionsBehavior.Editable option
不可寫
ColumnViewOptionsBehavior.Editable
Gets or sets whether end users are allowed to invoke cell editors
可讀可寫
OptionsColumn.AllowEdit
Gets or sets whether end users are allowed to invoke editors for the column's cells.
可讀可寫
只有ColumnViewOptionsBehavior.Editable=True 設置OptionsColumnAllowEdit 才有意義。
OptionsColumn.ReadOnly
Gets or sets whether end-users are prevented from editing the column's cell values.
可讀可寫
只讀不可拷貝:
ColumnViewOptionsBehavior.Editable = False
只讀可拷貝:
ColumnViewOptionsBehavior.Editable = True
OptionsColumn.AllowEdit = True
OptionsColumn.ReadOnly = True
可編輯:
ColumnViewOptionsBehavior.Editable = True
OptionsColumn.AllowEdit = True
OptionsColumn.ReadOnly = False
獲取選中行的值
代碼:private void gridData_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
_id=GWEntLib.Utilities.Mix.ConvertUtils.ToInt32(gridData.GetRowCellValu(e.FocusedRowHandle, "Id"));
_emrFileReadList = EMRTemplateFileReadList.GetEMRTemplateFileReadList(_id);
gridVersonData.DataSource = _emrFileReadList;
}
響應事件:FocusedRowChanged
獲取字段值:gridData.GetRowCellValue(e.FocusedRowHandle, "Id")
注意:FocusedRowChanged是Gridview的事件而不是gridControl的事件
gridControl與Gridview的區別:前者是容器,后者為視圖
全選/取消全選
private void Form1_Load(object sender, EventArgs e)
{
String str =@”
select cast( 0 as bit ) 選擇,ID,Name From dbo.Info”
DataTable dt =new DataTable();
dt =SqlHelper.ExecuteDataset(str).Tables[0];
gridView.DataSource =dt;

}
  #region 全選
private void tsbSelectAll_Click(object sender, EventArgs e)
{
for (int i = 0; i < gridView.RowCount; i++)
{
gridView.SetRowCellValue(i,gridView.Columns.ColumnByFieldName("選擇"), true);
}


}
#endregion

#region 取消全選
private void tsbUnSelectAll_Click(object sender, EventArgs e)
{
for (int i = 0; i < gridView.RowCount; i++)
{
gridView.SetRowCellValue(i, gridView.Columns.ColumnByFieldName("選擇"), false);
}

}

#endregion

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM