Click here to Skip to main content
15,891,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir,

I want to do that when user enter on Present cell of datagridview than the
cell value will change to Yes or No.

Below is my code to populate the data in datagridview from database

VB
Dim com As System.Data.SqlClient.SqlCommand
        Dim adpt As System.Data.SqlClient.SqlDataAdapter
        Dim build As System.Data.SqlClient.SqlCommandBuilder
        Dim dts As DataSet
        Dim table As DataTable
        Dim DBMS As New System.Data.SqlClient.SqlConnection
        DBMS.ConnectionString = (cnSettings2())
        Dim sql As String = "SELECT [ID],[Name],[Designation],[Present] FROM AttnDummy"
        DBMS.Open()
        com = New System.Data.SqlClient.SqlCommand(sql, DBMS)
        adpt = New System.Data.SqlClient.SqlDataAdapter(com)
        build = New System.Data.SqlClient.SqlCommandBuilder(adpt)
        dts = New DataSet()
        adpt.Fill(dts, "AttnDummy")
        table = dts.Tables("AttnDummy")
        DBMS.Close()
        dgv.DataSource = dts.Tables("AttnDummy")
        dgv.Columns(0).ReadOnly = True
        dgv.Columns(1).ReadOnly = True
        dgv.Columns(2).ReadOnly = True
        dgv.Columns(3).ReadOnly = False


Can anybody help me with code by which when user enter on that cell its value changes.
Posted
Updated 23-Aug-15 8:36am
v3

1 solution

You should take an Event from your DGV.
In this case it give to you the CellValueChanged-Event. This Event will also give you the DataGridViewCellEventArgs which sub-Options will help you with your issue.

For further help it could be necessary to know what you want to do ...
 
Share this answer
 
Comments
hspl 23-Aug-15 23:32pm    
can you help me with codes.
hspl 23-Aug-15 23:41pm    
When form opens by default all Present column value shows YES
I want to do like this, if user want to change any cell value of present column
from YES to NO or NO to YES by selecting that cell and pressing enter or space bar key.
Ralf Meier 24-Aug-15 0:24am    
Not clear what you tried to tell me.
Perhaps you give me an example.
Have you tried to work with the Event I have told to you ? And perhaps have you tried when it works and what it does ?

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