Click here to Skip to main content
14,363,083 members
Rate this:
Please Sign up or sign in to vote.
See more:
Respected Sir,
I need help on how can i change the datagridview particular cell value by double click on that cell.
Let say cell contain value ‘N’ when i double click on that particular cell it will change to ‘Y’.If anyone provide me the codes...

What I have tried:

Let say cell contain value ‘N’ when i double click on that particular cell it will change to ‘Y’.If anyone provide me the codes...
Posted
Updated 28-Aug-19 22:49pm
Comments
Maciej Los 29-Aug-19 5:15am
   
"What i have tried" section is used to provide a code you've tried. Repeating last statement of problem description is not the same as code. Agree?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Just handle the CellDoubleClick event:
private void myDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
    if (sender is DataGridView dgv)
        {
        DataGridViewCell cell = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex];
        if (cell.Value is string value && value == "N")
            {
            cell.Value = "Y";
            }
        }
    }

Private Sub myDataGridView_CellDoubleClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)
    If TypeOf sender Is DataGridView Then
        Dim dgv As DataGridView = CType(sender, DataGridView)
        Dim cell As DataGridViewCell = dgv.Rows(e.RowIndex).Cells(e.ColumnIndex)
        If TypeOf cell.Value Is String Then
            Dim value As String = CStr(cell.Value)

            If value = "N" Then
                cell.Value = "Y"
            End If
        End If
    End If
End Sub
   
v2
Comments
Madhu Chatterjee 29-Aug-19 7:29am
   
I need code in vb.net....
OriginalGriff 29-Aug-19 7:43am
   
So use an online converter, if you can't cope:
http://converter.telerik.com/
Should do it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100