2016-09-17 1 views
3

Ich fand viele ähnliche Fragen und Antworten, aber keine helfen mir mein Problem zu lösen.So deaktivieren Sie eine Schaltfläche in DataGridView, die nicht anklickbar ist (C# Windows-Anwendung)

Hier ein Screenshot von meiner Anwendung ist, wo ich dieses Problem dataGridView with buttoncell

Ich möchte (anklickbare oder nicht) deaktivieren, mit Blick auf bin die Taste, wenn Sie die Taste Text „AKZEPTIERT“ sagt hier ist das, was ich habe und das funktioniert nicht

 private void Cellcontent() 
    { 
     foreach (DataGridViewRow row in dataGridView1.Rows) 
     { 
      if ((row.Cells["Status"].Value.ToString()) == "ACCEPTED") 
      { 
       DataGridViewButtonCell cell = row.Cells["Status"] as DataGridViewButtonCell; 
       cell.ReadOnly = true; //if 1 cell will be disabled (not clickable) 

      } 
     } 
    } 

Antwort

0

hilft Ihnen folgendes tun könnte, wenn Sie Geist mit ein, eine andere Zelle nicht, wenn der Wert nicht ACCEPTED ist:

foreach (DataGridViewRow item in dataGridView1.Rows.OfType<DataGridViewRow>().Where(c => c.Cells[buttonCol.Index].Value != null && c.Cells[buttonCol.Index].Value.ToString() == "ACCEPTED")) 
{ 
    //you can replace the button with a textbox cell that contains the rejected value 
    item.Cells[buttonCol.Index] = new DataGridViewTextBoxCell { Value = "ACCEPTED" }; 
    item.Cells[buttonCol.Index].ReadOnly = true; 
    //note that you have to make a new button cell and replace the rejected ones if the status is updated later on to be able to use the button. 
} 

Hoffnung, das hilft.

Verwandte Themen