Solved

how to pass textbox data into a datagridview on a separate form in vb.net

Posted on 2009-05-04
2
3,487 Views
Last Modified: 2012-05-06
Hi, I have eight textboxes and corresponding labels on one form and one button. i have another form with a datagridview. On the click of the button on form1 i want to pass the content of the textboxes and corresponding labels' text into the datagridview on form2 only for those textboxes which are not empty. I would greatly appreciate a help in this matter in the form of syntax since i am a beginner in vb.net

Note: Its a vb.net windows application
0
Comment
Question by:moonis_ahmed
2 Comments
 
LVL 1

Accepted Solution

by:
k1karim earned 250 total points
Comment Utility
Hi, in my point of view you should check the TextBoxes Regardless of the labels, so put a proper Name for the text boxes and add them to Datagrid by text box name.
I wrote a small code for you and ask me if you had any question.

Private Sub Btn_Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Add.Click

        Dim frm2 As New Form2

'Find The Text Boxes Here

        For Each txtTest As Control In Me.Controls

            If txtTest.GetType().ToString() = "System.Windows.Forms.TextBox" Then

                'Check if it's not empty

                If txtTest.Text <> "" Then

'Make a New Record for DataGrid

                    Dim rw As New DataGridViewRow

'Get the Structure of the DataGrid and set it to New Row

                    rw.CreateCells(frm2.DataGridView1)

'Put the Data that you want in the right cell

                    rw.Cells(0).Value = txtTest.Text

                    rw.Cells(1).Value = txtTest.Name

'Add row to DataGrid

                    frm2.DataGridView1.Rows.Add(rw)

                    frm2.Show()

                End If

            End If

        Next

   End Sub

Open in new window

0
 
LVL 11

Expert Comment

by:srikanthreddyn143
Comment Utility
Or you can make a dataset in Form1 and Initialize Form2 with this dataset and load it.

Ex:

In Form1.
Add up all rows to dataset
Dim f2 As New Form2()
f2.Init(ds)
f2.show()

In Form2
Dim localds As DataSet
Public Sub Init(byVal ds As DataSet)
{
localds  = ds
}

publicSub  Load()
{
GridView1.DataSource = localds
Gridview1.DataBind()
}
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

9 Experts available now in Live!

Get 1:1 Help Now