CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: VB.NET

DataGridView

151 Views
Copy Code Show/Hide Line Numbers
   1:  Private Sub btnAdd_Click(ByVal sender As System.Object, _
   2:              ByVal e As System.EventArgs) Handles btnAdd.Click
   3:   
   4:          ' Check that the line item data is valid
   5:          If IsValidLineItem() Then
   6:   
   7:              ' Add a new row to the InvoiceLineItems table
   8:              InvoiceLineItemsBindingSource.AddNew()
   9:   
  10:              ' Set the values of the row in the data grid
  11:              Dim rowIndex As Integer = InvoiceLineItemsDataGridView.Rows.Count - 1
  12:              Dim row As DataGridViewRow _
  13:                  = InvoiceLineItemsDataGridView.Rows(rowIndex)
  14:              Dim cell As DataGridViewCell
  15:              cell = row.Cells(0)
  16:              cell.Value = 1
  17:              invoiceSequence += 1
  18:              cell = row.Cells(1)
  19:              cell.Value = invoiceSequence
  20:              cell = row.Cells(2)
  21:              cell.Value = AccountNoComboBox.SelectedValue
  22:              cell = row.Cells(3)
  23:              cell.Value = AccountNoComboBox.Text
  24:              cell = row.Cells(4)
  25:              cell.Value = DescriptionTextBox.Text
  26:              cell = row.Cells(5)
  27:              cell.Value = AmountTextBox.Text
  28:   
  29:              ' Save the line item to the table
  30:              InvoiceLineItemsBindingSource.EndEdit()
  31:   
  32:              ' Calculate the invoice total
  33:              Me.GetInvoiceTotal()
  34:   
  35:              ' Prepare for the next entry
  36:              DescriptionTextBox.Text = ""
  37:              AmountTextBox.Text = ""
  38:              DescriptionTextBox.Select()
  39:   
  40:          End If
  41:      End Sub
by mbbrennan
  January 02, 2010 @ 3:07pm

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate