Solved

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

Posted on 2009-05-04
2
3,714 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
Adding Existing Item to vb.net Project causes Errors 4 45
Help with preventing selection from a combobox 11 35
Open a link in vb.net 2 16
Code enhancement 4 22
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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