2013-06-28 107 views
0

每當我單擊一個複選框並查看單元格值已更改的事件時,如果該複選框本來是未選中的,並且始終爲true,如果該複選框最初被選中,則該值始終爲false ...RadGridView複選框控件始終爲false

更新: 所以,當我檢查框 - 然後細胞失去了焦點它變回原來的狀態 - 但不知道爲什麼?

爲什麼會這樣,我該如何解決這個問題?

private void CellValueChanged(object sender, GridViewCellEventArgs e) 
     { 
//e.Value always false or true depending on original state 
} 

更新:

填充的GridView

public void PopulateEvents(User user) 
     { 
      if (user.EventSubscriptions.Count < 1) 
       AddDefaultEvents(user); 

      var query = user.EventSubscriptions.Join(sp.Events, r => r.EventId, p => p.EventId, (r, p) => 
       new { r.UserId, r.EventSubscriptionId, p.EventType, p.EventAction, r.IsAlert, r.IsEmail, r.AlertLevel }) 
       .Where(pr => pr.UserId == user.ID); 

      BindingSource temp = new BindingSource() { DataSource = query }; 
      RGVAlerts.DataSource = temp; 

      //RGVAlerts.DataSource = query; 

      foreach (var column in RGVAlerts.Columns) 
      { 
       switch (column.HeaderText) 
       { 
        case "EventType": 
         column.HeaderText = "Category"; break; 
        case "EventAction": 
         column.HeaderText = "Event Action"; break; 
        case "IsAlert": 
         column.HeaderText = "Send Alert"; 
         column.ReadOnly = false; 
         break; 
        case "IsEmail": 
         column.HeaderText = "Send Email"; 
         column.ReadOnly = false; break; 

        case "AlertLevel": 
         column.HeaderText = "Alert Level"; break; 
       } 
      } 
      RGVAlerts.Columns.Remove("UserId"); 
      RGVAlerts.Columns.Remove("AlertLevel"); 
      RGVAlerts.Columns.Remove("EventSubscriptionId"); 

      GridViewComboBoxColumn comboLevel = new GridViewComboBoxColumn(); 
      comboLevel.DataSource = new string[] { "INFORMATION", "MILD", "SEVERE", "COUNT" }; 

      RGVAlerts.Columns.Add(comboLevel); 
      comboLevel.FieldName = "AlertLevel"; 
      comboLevel.HeaderText = "AlertLevel"; 

      RGVAlerts.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None; 
      foreach (GridViewDataColumn column in RGVAlerts.Columns) 
      { 
       column.BestFit(); 
       column.Width += 58; 

      }; 
      RGVAlerts.AllowCellContextMenu = true; 
      RGVAlerts.AllowEditRow = true; 
      RGVAlerts.CausesValidation = true; 

      RGVAlerts.Refresh(); 
     } 
+1

看起來您的綁定不正確。你能展示你用於網格初始化的代碼嗎? – RAS

+0

將更新問題 – jharr100

回答

1

在RadGridView複選框編輯器是一個永久的編輯器,當你改變當前單元格值將只改變。要在用戶選中複選框時強制更改該值,您需要訂閱RadGridView的ValueChanged事件並調用EndEdit方法:

void radGridView1_ValueChanged(object sender, EventArgs e) 
{ 
    if (radGridView1.CurrentColumn.Name == "MyCheckBoxColumnName") 
    { 
     radGridView1.EndEdit(); 
    } 
}