?
Solved

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

Posted on 2009-05-04
2
Medium Priority
?
3,938 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
k1karim earned 1000 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

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

801 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