none
How to commit combobox when selected item changed which is bind to datatable RRS feed

  • Question

  • Hi guys

    Can somebody tell me how to commit any changed on combobox this is my code, I've removed unnecessary code

    Private Sub FrmSalesOrder_Load(sender As Object, e As EventArgs) Handles Me.Load DTCustomer.Columns.Add("CUSTOMERID", GetType(System.Int32)) DTCustomer.Columns.Add("NAME", GetType(System.String)) CBoxCustomer.DataSource = DTCustomer CBoxCustomer.DisplayMember = "NAME" CBoxCustomer.ValueMember = "CUSTOMERID" DTSalesOrder.Columns.Add("SALESID", GetType(System.Int32)) DTSalesOrder.Columns.Add("CUSTOMERID", GetType(System.Int32)) CBoxCustomer.DataBindings.Add("SelectedValue", DTSalesOrder, "CUSTOMERID", True, DataSourceUpdateMode.OnValidation, -1) DTCustomer.Rows.Add(New Object() {DBNull.Value, "<Add New>"}) FirebirdDB.Adapter.SelectCommand.CommandText = "SELECT CUSTOMERID, NAME FROM CUSTOMER ORDER BY NAME ASC"   FirebirdDB.Adapter.Fill(DTCustomer)

    DTSalesOrder.Rows.Add(1, 1) DTChangedData = DTSalesOrder.GetChanges(DataRowState.Added) If DTChangedData IsNot Nothing Then 'InsertCommandSalesOrder() DTSalesOrder.AcceptChanges() End If End Sub Private Sub CBoxCustomer_Leave(Sender As Object, e As EventArgs) Handles CBoxCustomer.Leave, Me.BindingContext(DTSalesOrder).EndCurrentEdit() DTChangedData = DTSalesOrder.GetChanges(DataRowState.Modified) If DTChangedData IsNot Nothing Then 'UpdateCommandSalesOrder() DTSalesOrder.AcceptChanges() End If End Sub

    DTChangedData value is nothing when you delete text on combobox then you leave combobox by clicking a button, commit only happen when combobox leave using Tab button

    Best Regard

    Xan To






    • Edited by Xan To Thursday, November 22, 2018 1:45 AM
    Thursday, November 22, 2018 1:16 AM

Answers

  • I found the answer, hope this will help other, thanks

      Private Sub CBoxCustomer_TextChanged(Sender As Object, e As EventArgs) Handles CBoxCustomer.TextChanged
        CBoxCustomer.DataBindings.Item("SelectedValue").WriteValue()
      End Sub

    • Marked as answer by Xan To Thursday, November 22, 2018 9:49 PM
    Thursday, November 22, 2018 9:49 PM

All replies

  • Hello,

    My suggestion would be to save changes in the SelectedIndexChanged event of the ComboBox.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Proposed as answer by Alex Li-MSFT Thursday, November 22, 2018 7:05 AM
    Thursday, November 22, 2018 1:56 AM
    Moderator
  • Hi Karen, thank you for reply,

    But SelectedIndexChanged is not fire up when I delete text on combobox, please see this image

    Thursday, November 22, 2018 7:13 PM
  • I found the answer, hope this will help other, thanks

      Private Sub CBoxCustomer_TextChanged(Sender As Object, e As EventArgs) Handles CBoxCustomer.TextChanged
        CBoxCustomer.DataBindings.Item("SelectedValue").WriteValue()
      End Sub

    • Marked as answer by Xan To Thursday, November 22, 2018 9:49 PM
    Thursday, November 22, 2018 9:49 PM