Solved

getting text from a row in a datagrid

Posted on 2004-10-10
5
156 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 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Expando 4 34
AutoHotkey ActiveX Component Error 8 55
DataGridview Currency Formating? 22 38
Visual Studio editor? 1 16
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now