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 ....
Gremmy...
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!
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?
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..
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!
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!
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
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)
Re: How to pass values from textbox to datagridview in VB 2008?