开发者

How to disable a row by selecting value from comboBox in datagridview?

How to disable a row by selecting value from comboBox in datagridview?

Here I have a column name "Status" in which I am using ComboBox whose values are "Pending" and "Delivered" now I want that when a user selects the delivered from the ComboBox th开发者_StackOverflow社区en the entire row or this control should be disabled so user could not change it again and by default its value should be "Pending" how can i do it? Is it possible to disable a single row in gridview?


You cannot disable an individual row. However you can make it readonly:

DataGridView1.Rows[rowIndex].ReadOnly = true;

(This makes row with index of rowIndex set to readonly).

For your specific example, you would want to handle the CellValueChanged event of the datagridview and have code along the lines of:

        void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 4 && DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "Delivered")
            {
                DataGridView1.Rows[e.RowIndex].ReadOnly = true;
            }
        }


You can handle the RowChanged event and do something like

if (Status == 'Delivered')
{
   e.Row.Enabled = False;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜