Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 21: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

Just handle the CellDoubleClick event:
C#
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";
            }
        }
    }

VB
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
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900