Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

getting text from a row in a datagrid

Posted on 2004-10-10
5
Medium Priority
?
208 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
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
123654789987 earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

885 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