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!
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 ....
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
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!
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)
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!
Bookmarks