Click here to Skip to main content
15,891,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I have created a gridview which contains columns like patient name,test name,test id,date. i want to get the value of the the selected row and store in a variable and when i click on proceed button thn i shud be able to pass the selected values on next page
Posted

hiee

u can use this Code

'=============Form which Contains Grid==============='
Private sub Proceed()
Dim SR as new SelectedRow

Sr.Col1 = DataGrid.SelectedRows(0).Cells(0).Value.ToString()
Sr.Col2 = DataGrid.SelectedRows(0).Cells(1).Value.ToString()
Sr.Col3 = DataGrid.SelectedRows(0).Cells(2).Value.ToString()
Sr.Col4 = DataGrid.SelectedRows(0).Cells(3).Value.ToString()
Dim Frm2 as New Form2(SR)
Frm2.Show
End Sub
'===============End==============='

'============Make a New Class============'
Class SelectedRow

Public Col1 as String
Public Col2 as String
Public Col3 as String
Public Col4 as String

End Class
'===========End========='



'===============New Form to Show your Selected Row Values============'
Class Form2

Public Sub New(ByVal objSelectedRow as SelectedRow)
dim Val1 as string = objSelectedRow.Col1
dim Val2 as string = objSelectedRow.Col2
dim Val3 as string = objSelectedRow.Col3
dim Val4 as string = objSelectedRow.Col4
End Sub

End Sub
'==============End===================='


Regards

www.masssoftech.blogspot.com
 
Share this answer
 
What I would do is create a class that exposes the row values as public properties. In the second form I would have a variable that returns an instance of that class. Then I would create a constructor for the second form that accepts an instance of the class as a parameter. Then I would retrieve the info from the selected row, ceate an instance of my class, and call my second form using my instantiated class in the constructor.

Happy Coding
 
Share this answer
 

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