2013-10-11 45 views
0

我在DevExpress XtraGrid控件中檢查了一個問題。Dev Express XtraGrid複選框

我在代碼中創建了未綁定的列(不是通過嚮導),並且該複選框無法通過鼠標進行檢查。

這裏是我的代碼:

Private Sub DataViewFrm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    Dim data As New DataTable 
    data=getDataTable("select....") 

    gridViewer.DataSource = data 

    Dim Tick As New RepositoryItemCheckEdit() 

    gridViewer.Refresh() 

    Dim unbColumn As GridColumn = gridvwViewer.Columns.AddField("Coba") 
    unbColumn.VisibleIndex = gridvwViewer.Columns.Count 
    unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Boolean 
    unbColumn.OptionsColumn.AllowEdit = True 
    unbColumn.OptionsColumn.ReadOnly = False 

    gridvwViewer.Columns(8).ColumnEdit = Tick  
End Sub 

下面是結果:screenshot

回答

2

你應該處理ColumnView.CustomUnboundColumnData事件提供未綁定列的數據。
這裏是讀/寫方案(C#)的ColumnView.CustomUnboundColumnData事件使用的演示:

//... 
var unbColumn = gridView1.Columns.AddField("Coba"); 
unbColumn.VisibleIndex = gridView1.Columns.Count; 
unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Boolean; 
CobaValues = new Dictionary<int, bool>(); 
gridView1.CustomUnboundColumnData += gridView1_CustomUnboundColumnData; 

//... 
IDictionary<int, bool> CobaValues; 
void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) { 
    if(e.Column.FieldName == "Coba") { 
     if(e.IsGetData) { 
      bool value; 
      if(CobaValues.TryGetValue(e.ListSourceRowIndex, out value)) 
       e.Value = value; 
     } 
     if(e.IsSetData) { 
      CobaValues[e.ListSourceRowIndex] = (bool)e.Value; 
     } 
    } 
}