Hello All,
I'm new to .Net (VB 2005) and would like some advice on what methodology should be used to populate a DataGridView.
The scenario is an orders screen with some text fields such as txtOrderItem, txtOrderQTY and a DataGridView. When a button cmdAddItem is pressed the data in the textboxes is added to the DataGridView as a new row.
Here's what I've tried for this sample:
Now when I try to add code to the cmdAddItem such as:
The IDE shows me that dtOrderItems is not declared and therefore there is no NewRow() method available.
So my questions are:
1. How to declare objects or variables so that they are available within procedures in a form but not outside the form.
2. Whats the best (preferred) way to populate a DataGridView without binding to a database (I'll write to the database after all the items are entered in the datagridview).
Any help or guidance is very much appreciated.
Thanks,
Rory
I'm new to .Net (VB 2005) and would like some advice on what methodology should be used to populate a DataGridView.
The scenario is an orders screen with some text fields such as txtOrderItem, txtOrderQTY and a DataGridView. When a button cmdAddItem is pressed the data in the textboxes is added to the DataGridView as a new row.
Here's what I've tried for this sample:
Code:
Imports System.Data
Public Class frmOrdersIn
Private Sub frmOrdersIn_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Create a datatable for the orders DataGridView
Dim dtOrderItems As DataTable
dtOrderItems = New DataTable("OrdersList")
Dim Product As DataColumn = New DataColumn("Item")
Dim Product As DataColumn = New DataColumn("Qty")
Code:
Private Sub cmdAddItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddItem.Click
OrderItem = dtOrderItems.NewRow()
OrderItem("Item") = txtOrderItem.Text
OrderItem("QTY") = txtOrderQTY.Text
dtOrderItems.Rows.Add(OrderItem)
So my questions are:
1. How to declare objects or variables so that they are available within procedures in a form but not outside the form.
2. Whats the best (preferred) way to populate a DataGridView without binding to a database (I'll write to the database after all the items are entered in the datagridview).
Any help or guidance is very much appreciated.
Thanks,
Rory