foreach (DataGridViewRow dgvrow in dataGridView1.SelectedRows)
{
if (Convert.ToBoolean(dgvrow.Cells["chkbox"].Value) == true)
{
LOB = dgvrow.Cells["lOBDataGridViewTextBoxColumn"].Value.ToString();
POL_NUM = dgvrow.Cells["polNumDataGridViewTextBoxColumn"].Value.ToString();
POL_Effdate = Convert.ToDateTime(dgvrow.Cells["polEffDtDataGridViewTextBoxColumn"].Value);
POL_Expdate = Convert.ToDateTime(dgvrow.Cells["polExpDtDataGridViewTextBoxColumn"].Value);
tbl_pol_coll_agmt_dtls_id = Convert.ToInt32(dgvrow.Cells["TBL_POL_COLL_AGMT_DTLS_ID"].Value);
if (MessageBox.Show("Would like to update the click yes!!",
"Input Policy", MessageBoxButtons.YesNo) ==
System.Windows.Forms.DialogResult.Yes)
{
collServcall.UpdateInputPolicyData(tbl_pol_coll_agmt_dtls_id, LOB, POL_NUM, POL_Effdate, POL_Expdate);
}
}
}
在這里,我提到了復選框值是否為真,但只需要使那些單元格可編輯,其余行或單元格應該是只讀的
uj5u.com熱心網友回復:
如何使特定行可編輯
CellBeginEdit如果滿足不編輯的條件,您應該處理資料網格視圖的事件并取消編輯。我將提供一個演示代碼,您可以更改并適應您的解決方案。
看看下面的例子。在此示例中,不允許編輯具有偶數索引號的行。
private void DataGridView1_CellBeginEdit(object sender,
DataGridViewCellCancelEventArgs e)
{
if (e.RowIndex % 2 == 0)
{
e.Cancel = true;
}
}
所以,你也應該這樣做。
如何使標記了復選框的特定行可編輯,而其他行應為只讀
假設如果您有一個名為的資料網格視圖復選框列checkBoxColumn,那么您應該執行以下操作。(演示代碼)
private void DataGridView1_CellBeginEdit(
object sender, DataGridViewCellCancelEventArgs e)
{
// For this demo we will make exception for checkBoxColumn itself.
// So it is always editable.
if (e.ColumnIndex != checkBoxColumn.Index)
{
object rawValue = dataGridView1[checkBoxColumn.Index, e.RowIndex].Value;
bool value = rawValue is bool ? (bool)rawValue : false;
// But if checkBoxColumn is checked then editing not allowed
if (!value)
{
e.Cancel = true;
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/489385.html
