2016-02-08 109 views
-2

我有DataGridView的CheckBox列(Header:Status)和Textbox Column(Header:Quantity)。我想自動選中該複選框列如果數量爲0c#datagridview複選框檢查其他列的值是否爲0

enter image description here

+3

所以給它一個嘗試 – ethorn10

+0

@ ethorn10我只一個學生..我的教授只教C#的基本.. ..我研究和嘗試這從2015年11月,但我不能這樣做..這就是爲什麼我在這裏問 (對不起,我的英語,我希望你會明白) –

回答

1

循環遍歷行,如果像這樣的datagridview:

foreach (DataGridViewRow row in dataGridView1.Rows) 
{ 
    //Check Column 3 for quantity   
    if (row.Cells[3].Value.ToString() == "0") 
    { 
     //Get checkbox in column 1 and cast it to a checkbox 
     DataGridViewCheckBoxCell cell = row.Cells[1] as DataGridViewCheckBoxCell;  
     cell.Value = cell.TrueValue; 
    } 
} 
+0

大謝謝給你!! cell.Value == cell.TrueValue有錯誤;但我刪除了一個=(等號),它的工作原理..再次感謝.. :) –

+0

不客氣。對不起,這是一個錯字。 –

+0

先生..你知道如何將它保存到訪問數據庫嗎?在datagridview中檢查的複選框,但沒有保存到訪問數據庫..我使用更新語句,但它沒有工作 –

相關問題