-
February 23rd, 2009, 06:41 AM
#1
How to pass values from textbox to datagridview in VB 2008?
i used a split container, in the 1st panel, i put the textbox for the user to input the values. In the 2nd panel, i put the datagridview to output the values that the user inputted. Now, i don't know and i cannot find way how to print the values into the datagridview from the textbox. please help me. thanks!
-
February 23rd, 2009, 07:34 AM
#2
Re: How to pass values from textbox to datagridview in VB 2008?
Create a class object to hold the information for the Datagridview.. create a variable as a List Of (object) and set it as the Datasource for the Datagridview..
Every time the text entry is completed add it to the list and update/Refresh the Datagridview ....
Gremmy...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
February 23rd, 2009, 08:03 AM
#3
Re: How to pass values from textbox to datagridview in VB 2008?
Can you please show me a sample code? So i can understand more because i'm a newbie and cannot understood some terms. Thanks!
-
February 23rd, 2009, 08:13 AM
#4
Re: How to pass values from textbox to datagridview in VB 2008?
Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim num1, num2, num3 As Integer
num1 = TextBox2.Text
num2 = TextBox3.Text
num3 = num2 * num1
TextBox4.Text = num3
End Sub
--->This is my input code
Public Property DataSource() As Object
Get
End Get
Set(ByVal value As Object)
End Set
End Property
---> This is my output code. Can you please help me to fill up?
-
February 23rd, 2009, 08:26 AM
#5
Re: How to pass values from textbox to datagridview in VB 2008?
Your part of the way there .... so lets fill up ...
Code:
Public Class DataGridData
Private _Text As String
#Region "Properties"
Public Property Text() As String
Get
Return _Text
End Get
Set(ByVal Value As String)
_Text = Value
End Set
End Property
#End Region
End Class
Above is you class object that you can now use to add lists of text to the datagridview...
Next we need to declare a few items...
Code:
Private DGVdata As List(Of DataGridData)
Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim num1, num2, num3 As Integer
num1 = TextBox2.Text
num2 = TextBox3.Text
num3 = num2 * num1
TextBox4.Text = num3
TmpDGVData.Text = TextBox4.Text
'Create a new entry
Dim TmpDGVData As New DataGridData
DGVdata.Add (TmpDGVData)
'Update the Datagridview...
RefreshDGV()
End Sub
Private Sub RefreshDGV()
DataGridView1.DataSource = DGVdata
End Sub
This i think should help you get started...
Gremmy..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
February 23rd, 2009, 08:44 AM
#6
Re: How to pass values from textbox to datagridview in VB 2008?
I tried to run it but when i clicked the button but there's an error. "NullReferenceException was unhandled. Object reference not set to an instance of an object." Please help me. Thanks!
-
February 23rd, 2009, 09:01 AM
#7
Re: How to pass values from textbox to datagridview in VB 2008?
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("CD/DVD Burning".ToString)
ComboBox1.Items.Add("Downloads".ToString)
ComboBox1.Items.Add("Printing".ToString)
ComboBox1.Width = 100
End Sub
Private Sub TabPage1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub SplitContainer1_Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles SplitContainer1.Panel1.Paint
End Sub
Private Sub Transaction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Public Class DataGridData
Private _Text As String
#Region "Properties"
Public Property Text() As String
Get
Return _Text
End Get
Set(ByVal Value As String)
_Text = Value
End Set
End Property
#End Region
End Class
Private DGVdata As List(Of DataGridData)
Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create a new entry
Dim TmpDGVData As New DataGridData
DGVdata.Add(TmpDGVData)
Dim quantity, price, totalAmount As Integer
quantity = TextBox2.Text
price = TextBox3.Text
totalAmount = quantity * price
TextBox4.Text = totalAmount
TmpDGVData.Text = TextBox4.Text
'Update the Datagridview...
RefreshDGV()
End Sub
Private Sub RefreshDGV()
DataGridView1.DataSource = DGVdata
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
End Class
--->This is my whole code. Still gets this error when i run it. "A first chance exception of type 'System.NullReferenceException' occurred in ic.exe" Please help me. Thanks a lot!
-
February 23rd, 2009, 11:40 PM
#8
Re: How to pass values from textbox to datagridview in VB 2008?
Please go back and use CODE TAGS around your code
Code:
' so we CAN READ IT
' the way you wrote IT!
also, highlight the line that crashes, and give the exact error message
-
February 24th, 2009, 02:23 AM
#9
Re: How to pass values from textbox to datagridview in VB 2008?
Like i said i gave you enough to get started...
all that is missing is in the form load sub add...
Code:
DGVdata = New List(Of DataGridData)
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
March 1st, 2009, 08:34 PM
#10
Re: How to pass values from textbox to datagridview in VB 2008?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|