datagridviewcomboboxcolumn update niet

Status
Niet open voor verdere reacties.

bodylojohn

Gebruiker
Lid geworden
9 nov 2006
Berichten
70
Beste mensen,

Ik heb een form met een datagridvieww.
In dit DGV heb ik een datagridviewcomboboxcolumn gedefinieerd.
Deze laat ook netjes de juiste data zien.

Het probleem is echter dat als ik op de update button klik de data niet opgeslagen wordt.

Ik ben hier nu al weken mee aan het puzzelen maar kan het maar niet oplossen.


hieronder staat de code die ik tot nu toe heb:
Code:
Imports System
Imports System.Data
Imports System.Data.OleDb

Public Class frmRIT_INFO
  Private bindingSource1 As New BindingSource()
  Private bindingSource2 As New BindingSource()
  Private dataAdapter1 As New OleDbDataAdapter()
  Private dataAdapter2 As New OleDbDataAdapter()

  Private Sub frmRIT_INFO_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Me.Dispose()
  End Sub

  Private Sub frmRIT_INFO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    GetDataTruck()
    Me.Column1.DisplayMember = "Kenteken"
    Me.Column1.ValueMember = "Wagen_ID"
    Me.Column1.DataSource = Me.bindingSource2

    GetDataRit()
    Me.DataGridView1.DataSource = Me.bindingSource1
    Me.DataGridView1.AllowUserToAddRows = False

    ' Make sure that the columns get displayed in the same order as entered in the query "SELECT	Datum,Wagen_ID,Chauffeur_ID,..."
    ' The datagridviewcombocolumn has the same index as the column in the query its refered to.
    For Each column As DataGridViewColumn In Me.DataGridView1.Columns
      column.DisplayIndex = column.Index
    Next

  End Sub

  Private Sub GetDataRit() 'Childdata to populate the DGV
    Dim sql As String = String.Format("SELECT	Datum,Wagen_ID,Chauffeur_ID,Beginstand,Eindstand,Liter,Dieselkoeling,Stops,StopsDachser,BrutoUren,Maut,Eurovignet FROM tblRIT")
    Me.dataAdapter1 = New OleDbDataAdapter(sql, _Connectionstring)
    Dim commandBuilder As New OleDbCommandBuilder(Me.dataAdapter1)
    Dim table As New DataTable()
    table.Locale = System.Globalization.CultureInfo.InvariantCulture
    Me.dataAdapter1.Fill(table)
    Me.bindingSource1.DataSource = table
  End Sub

  Private Sub GetDataTruck() 'Parentdata to populate the datagridviewcombobox
    Dim sql As String = String.Format("SELECT Wagen_ID, Kenteken from tblWAGEN")
    Me.dataAdapter2 = New OleDbDataAdapter(sql, _Connectionstring)
    Dim commandBuilder As New OleDbCommandBuilder(Me.dataAdapter2)
    Dim table As New DataTable()
    table.Locale = System.Globalization.CultureInfo.InvariantCulture
    Me.dataAdapter2.Fill(table)
    Me.bindingSource2.DataSource = table
  End Sub

  Private Sub DataGridView1_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
    Dim value As String = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()
    Dim headerText As String = DataGridView1.Columns(e.ColumnIndex).HeaderText

    ' Abort validation if cell is not in the CompanyName column. 
    If Not headerText.Equals("Beginstand") Then Return

    ' Confirm that the cell is not empty. 
    If (String.IsNullOrEmpty(e.FormattedValue.ToString())) Then
      DataGridView1.Rows(e.RowIndex).ErrorText = _
          "Company Name must not be empty"
      e.Cancel = True
    Else ' Check the entered value for number
      If Not (Char.IsDigit(e.FormattedValue)) Then
        DataGridView1.Rows(e.RowIndex).ErrorText = _
          "De waarde moet een nummer zijn!"
        e.Cancel = True
      End If
    End If
  End Sub

  Private Sub dataGridView1_CellEndEdit(ByVal sender As Object, _
      ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
      Handles DataGridView1.CellEndEdit

    ' Clear the row error in case the user presses ESC.   
    dataGridView1.Rows(e.RowIndex).ErrorText = String.Empty
  End Sub
  Private Sub ToolStripButton_CloseWindow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton_CloseWindow.Click
    Me.Close()
  End Sub

  Private Sub ToolStripButton_Insert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton_Insert.Click
    Me.DataGridView1.AllowUserToAddRows = True
    'Scroll to the new row
    Me.DataGridView1.FirstDisplayedScrollingRowIndex = Me.DataGridView1.RowCount - 1
    'Make the first cell in the new row the current cell
    DataGridView1.CurrentCell = DataGridView1(0, Me.DataGridView1.RowCount - 1)

    'DataGridView1.BeginEdit(False)
  End Sub

  Private Sub ToolStripButton_Update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton_Update.Click
    Me.bindingSource1.EndEdit()
    Me.dataAdapter1.Update(CType(Me.bindingSource1.DataSource, DataTable))
    Me.DataGridView1.AllowUserToAddRows = False
  End Sub

  Private Sub ToolStripButton_Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton_Delete.Click
    If MessageBox.Show("Wilt u deze rij verwijderen ?", "Verwijder", MessageBoxButtons.YesNo) = DialogResult.Yes Then
      If Not DataGridView1.Rows(DataGridView1.SelectedCells(0).RowIndex).IsNewRow Then
        DataGridView1.Rows.RemoveAt(DataGridView1.SelectedCells(0).RowIndex)
        Me.dataAdapter1.Update(CType(Me.bindingSource1.DataSource, DataTable))
      End If
    End If
  End Sub
End Class

k hoop dat mij iemand kan helpen met deze uitdaging..

Alvast bedankt!!!!
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan