2011-12-27 124 views
1

我已經加入datagridview的一個複選框列和動態的DataGridView中添加的每一行的值問題與DataGridView的複選框列

現在,當我點擊的DataGridView排序的第一行復選框被自動取消選中

我已經在datagridview的 再次將數據綁定的DataGridView的排序事件編寫的代碼,但仍是第一行復選框列未被選中自動

這裏是我的代碼

if (attachedActiveStatus.ContainsKey(row.Cells["ServerId"].Value.ToString())) 
      { 

       DataGridViewCheckBoxCell cell1 = (DataGridViewCheckBoxCell)row.Cells[0]; 
       cell1.Value = true; 

       row.Cells[0].Value = "true"; 

       row.Cells[4].Value = attachedPriority[row.Cells["ServerId"].Value.ToString()]; 

       switch (attachedActiveStatus[row.Cells["ServerId"].Value.ToString()]) 
       { 
        case "0": 
         row.Cells["Status"].Value = "Offline"; 

         break; 

        case "1": 
         row.Cells["Status"].Value = "Active"; 

         break; 

        case "2": 
         row.Cells["Status"].Value = "Inactive"; 

         break; 

       } 


      }   
+0

你能把你的代碼放在這裏嗎? – 2011-12-27 10:42:34

+0

這是屬於winform還是asp.net,有更多的標籤可用? – V4Vendetta 2011-12-27 10:51:04

+0

如果你像上面那樣添加,那麼你在排序的事件中綁定了什麼/如何綁定,這個複選框的值是否爲false? – V4Vendetta 2011-12-27 11:08:37

回答

0

我認爲你的問題可能是由於以下行:

row.Cells[0].Value = "true"; 

這是設置再次複選框的值,你已經在該行已經設置立即在上面:

cell1.Value = true;