none
DataGridViewComboBoxColumn not saving last value selected RRS feed

  • Question

  • I have a datagrid view that saves the selected values except the last value.
    If the user selects a value from 3 different datarows, only the last value is not saved.


    Any help is greatly appreciated.  Thank you !


    Private Sub Button_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Save.Click
        myDataset.AcceptChanges()
        myDataset.WriteXml(strTempFile)
        myDataset.Dispose()
        CleanupNotes()
    End Sub

    Sub Bind Statuses()
        CB_RecStatus.DataSource = Array_RecStatusBoxValues
    End Sub


    Sub DefineColumns()
    With DGV_Kits
        Dim RecStatus As New DataGridViewComboBoxColumn
        With RecStatus
            .DataPropertyName =
    "RecStatus"
            .HeaderText = "Rec Status"
            .DataSource = Array_RecStatusBoxValues
            .AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None
            DataGridViewCellStyle26.Font =
    New System.Drawing.Font("Arial", 8.0!)
            .DefaultCellStyle = DataGridViewCellStyle26
            .Name =
    "RecStatus"
            .ReadOnly = False
            .Resizable = System.Windows.Forms.DataGridViewTriState.[False]
            .ToolTipText =
    "Record Status"
            .Width = 104
            .MaxDropDownItems = 9
        End With
        .Columns.Add(RecStatus)
    End With


    Sub BindColumns()
        dv = myDataset.Tables("Kit").DefaultView
        dv.RowFilter =
    ""
        strNumberofRows = dv.Count
        DGV_Kits.DataSource = dv
    End Sub
    Monday, August 4, 2008 9:12 PM

All replies

  • Does anyone have any ideas?  Any pieces I am missing?  Any direction as to what I should read?

    Any and suggestions are welcome.

    Thank you
    Tuesday, August 5, 2008 3:38 PM
  • pcombs said:

    I have a DataGridView that saves the selected values except the last value.
    If the user selects a value from 3 different datarows, only the last value is not saved.


    Hi pcombs,

    Welcome to MSDN forums!

    Could you please clarify your question and post repro steps?

    Code sample: Update (Insert/Update/Delete/Save) data back into MS Access database from DataGridView.
    Imports System.Data.OleDb     
        
    Public Class Form1     
        
        Dim myDA As OleDbDataAdapter     
        Dim myDataSet As DataSet     
        
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load     
            Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=|DataDirectory|\myDB.mdb")     
            Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Table1", con)     
            con.Open()     
            myDA = New OleDbDataAdapter(cmd)     
            'One CommandBuilder object is required. It automatically generates DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object     
            Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(myDA)     
            myDataSet = New DataSet()     
            myDA.Fill(myDataSet, "MyTable")     
            DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView     
            con.Close()     
            con = Nothing    
        End Sub    
        
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click     
            Me.Validate()     
            Me.myDA.Update(Me.myDataSet.Tables("MyTable"))     
            Me.myDataSet.AcceptChanges()     
        End Sub    
        
    End Class   

    In addition, select/highlighten your database file in Solution Explorer -> Properties Pane -> Set the "copy to ouput directory" property vaule as "copy if newer", otherwise you don't see the database changes (as if the database were not saved/updated) when you restart your application.


    Check the following thread for reference:
    http://forums.msdn.microsoft.com/en-US/vbgeneral/thread/d504018e-e8b0-4b0a-a3b4-dfbeec1f682b
    Four methods to making simple Data Access application(Next, Previous, First, Last, Update, Delete, Insert, Save) in VB.NET.


    More appropriate forum:
    Windows Forms » Windows Forms Data Controls and Databinding


    Best regards,
    Martin Xie

    Monday, August 11, 2008 8:41 AM