0

I created a datagridview via the UI editor and added columns. One of the columns is DataGridViewComboBoxColumn.

I'm not sure which event of the DataGridView to use to populate the data from the database to the combobox in dgv.

DataGridViewComboBoxColumn dcombo = (DataGridViewComboBoxColumn) adresesDataGridView.Columns["cityColumn"];
dcombo.DataSource = this.CityDataTable();
dcombo.DisplayMember = "city";
dcombo.ValueMember = "id";
Ivan
  • 5,139
  • 11
  • 53
  • 86
  • Probably the event is when you set the DataSource of your DataGridView. Or do you mean that you need to filter the data this ComboBox holds, in relation to the current Row / Cell / other selection? – Jimi Aug 06 '23 at 16:23
  • I not need for filter. Form show partner data and partner can have many adresses which i want to show and specific tab with DGV and also he can add new rows but only city column have combobox. – Ivan Aug 06 '23 at 16:27
  • Well, you have to filter something to fill `CityDataTable`. Assuming the database is normalized, either this DataTable contains the *cities of all partners*, with a Foreign Key that identifies the *Partner ID* or a *City ID* (unless you have, e.g., LEFT JOIN(ed) two tables, but in this case the *partners* list would be a DISTINCT re-filter), or you have to re-query the database for each *partner* selected, specifying a similar filter. I.e, how did you plan to fill `CityDataTable`, based on you db structure? – Jimi Aug 06 '23 at 17:18
  • The grid event is RowsAdded or you could iterate rows after the data is bound. See [visual basic example](https://stackoverflow.com/questions/26986557/how-to-programatically-populate-a-datagridviewcomboboxcolumn-in-vb-net). – derloopkat Aug 06 '23 at 17:34

0 Answers0