Combobox in datagridview, fire method on selectedindexchange

lkubler 41 Reputation points


I have a combobox added to a datagridview. Currently, when the user makes a selection in the combobox they need to hit a button on the form that writes the data back to the backend database and then refreshes the datagridview to reflect this change plus any other changes made by other users. Works Ok but I was thinking it would be better if it would automatically perform this refresh of the data when the user selects an item in the combobox.

frmRefresh() is the method that is called when the Refresh button is clicked, I thought it would be simple enough to all it from the combobox_selectedIndexChanged method but that did not work.

What am I missing?

Thanks in advance!

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,373 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,201 Reputation points


    The following code sample shows how to work with a ComboBox columns in a DataGridView. When a change is made to either DataGridViewComboBox a method, [CurrentValuesView][2] has the new values. From here you can update your database. No buttons needed.

    There is one button but that can be totally ignored.

    What's left? pass changes to a method that updates the table(s).

    • Data script included
    • Actual database type does not matter so the code can be adapted to any database



    1 person found this answer helpful.
    0 comments No comments