0

I am building a dispatchers application for the Red Cross in my region. The dispatcher will see a list (DataGridView) with all units under his/her control. Each row (unit) has 7 columns.

eid (text) 
roepnr (text) 
locatie (ComboBox) 
melding (text) 
telefoon (text) 
functie (text)
status (ComboBox)

The items in both ComboBoxes must be added programmatically. The items are listed in tables in the database. This is because the dispatcher (or supervisor) must be able to add items like locations, statuses etc.

How can I add these units to the DataGridView and have the correct Locatie and Status be selected? Both are integer columns in the units table in the database. The integers are the foreign keys which correspond with the primary keys in the tables "locaties" and "statussen."

First I thought I could use the DataSource property to add the units to the DataGridView. But I'm not sure how I can have the correct items selected in the ComboBoxes and have the items added to the ComboBoxes.

The database is a MySql database!

4

1 回答 1

0

您不只是希望组合框列中的选项成为两个表的主键字段的内容吗?所以:

string[] locaties = <SELECT primary key field from locaties>
var cbColLocaties = dataGridView1.Columns[2] as DataGridViewComboBoxColumn;
cbColLocaties.DataSource = locaties;

string[] statussen = <SELECT primary key field from statussen>
var cbColStatussen = dataGridView1.Columns[6] as DataGridViewComboBoxColumn;
cbColStatussen.DataSource = statussen;

...或使用从查询返回到数据库中的任何可枚举集合,而不是使用string[]

于 2012-02-07T01:13:05.140 回答