Solved

getting text from a row in a datagrid

Posted on 2004-10-10
5
197 Views
Last Modified: 2010-04-23
I have a datagrid that has the first column as a boolean checkbox and the other 5 columns are textbox controls. The user will click the check box for their selection and then I want to get the values of each text box in that row to display on the next form, so I want to populate some variables to pass. How do I achieve this?

0
Comment
Question by:netravel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
123654789987 earned 500 total points
ID: 12273876
You have to loop through each row in the datagrid,

Dim dataTable = datagrid.DataSource
Dim firstcolumn as string
Dim seconColumn as string

for i = 0 to dataTable.Rows.Count -1
if(ctype(datagrid.Item(i,0) , boolean)
firstcolumn  = ctype(datagrid.Item(i,1) , string)
secondColumn = ctype(datagrid.Item(i,2) , string)
End if
Next i


Public Property FirstColumn As string
   Get
      Return firstcolumn  
   End Get
   Set
      firstcolumn  = value
   End Set
End Property

Public Property SecondColumn As string
   Get
      Return secondColumn
   End Get
Set
      secondColumn = value
   End Set
End Property

U can access these properties from form2.

Dim frm1 as Form1
frm1 = new Form1
 Dim str as string = frm1.FirstColumn // Like this
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12273878
Hi,
Try This,
On the event click of the colmen checkbox use this to get the other values,


Dim Field1, Field2, Field3, Field4, Field5 As String
Field1 = Convert.ToString(DataGrid1.Item(0, DataGrid1.CurrentRowIndex))
Field2 = Convert.ToString(DataGrid1.Item(1, DataGrid1.CurrentRowIndex))
Field3 = Convert.ToString(DataGrid1.Item(2, DataGrid1.CurrentRowIndex))
Field4 = Convert.ToString(DataGrid1.Item(3, DataGrid1.CurrentRowIndex))
Field5 = Convert.ToString(DataGrid1.Item(4, DataGrid1.CurrentRowIndex))

GL
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12273885
Sorry, a little mistake :P

Try This

Dim Field1, Field2, Field3, Field4, Field5 As String
Field1 = Convert.ToString(DataGrid1.Item(DataGrid1.CurrentRowIndex,0))
Field2 = Convert.ToString(DataGrid1.Item(DataGrid1.CurrentRowIndex,1))
Field3 = Convert.ToString(DataGrid1.Item(DataGrid1.CurrentRowIndex,2))
Field4 = Convert.ToString(DataGrid1.Item(DataGrid1.CurrentRowIndex,3))
Field5 = Convert.ToString(DataGrid1.Item( DataGrid1.CurrentRowIndex,4))

GL
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question