Combobox in datagridview, fire method on selectedindexchange

asked 2021-05-05T17:08:04.13+00:00
lkubler 41 Reputation points

Hi,

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!

C#
C#
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.
6,927 questions
{count} votes

1 answer

Sort by: Most helpful
  1. answered 2021-05-05T18:32:59.307+00:00
    Karen Payne MVP 29,226 Reputation points Microsoft MVP

    Hello,

    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

    94030-figure1.png

    ---
    94056-codedbykpmvp.png

    No comments