Click here to Skip to main content
15,850,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone

I am facing problem in selecting a row in data grid . i am using current row index in following code. but it is not working.

Private Sub dgvEmployeedetails_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvEmployeedetails.CellContentClick

Public Event RowCommand As GridViewCommandEventHandler
        Dim i As Integer
        i = dgvEmployeedetails.CurrentRowIndex()
        dgvEmployeedetails.Item(.CurrentRowIndex, 0)
       dgvEmployeedetails.Item(.CurrentRowIndex, 1)
End Sub

where dgvEmployeedetails is data grid name. in which i have 2 colums which is number and name. my requirement is i should be able to select  both columns  when i click with mouse pointer in data grid and all data related to it must be retrived  from database in appropiate fields.     kindly help me how to code. to fulfil my above requirement

1 solution

Dim ContactName As String
ContactName = dgContactList.CurrentRow.Cells(0).Value

where cells(0) is the column number that you want, remembering that 0 is the first column
Share this answer
Dalek Dave 3-Aug-10 10:32am    
Couldn't put it better myself!
parchuri08 4-Aug-10 1:01am    
Hi Simon
Firstly i thanks alot for advice.But it is giving me error as expression missing at ContactName i didnt understand what is meant my dgContactList.
Simon_Whale 4-Aug-10 5:16am    
sorry that code is from one of my projects, you need to replace dgContactList with dgvEmployeedetails
parchuri08 6-Aug-10 5:27am    
yes simon i did that . now there is no error only exception is coming indicating as string cannot be taken. anyway i will look in to that.Nice to have response from you.

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