Solved

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

Posted on 2009-05-04
2
3,580 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
ID: 24294693
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
ID: 24296213
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

24 Experts available now in Live!

Get 1:1 Help Now