Solved

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

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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