Found a bunch of other threads about comboboxes in WPF datagrid, but none that helped.
I have a connection to a MySQL database, and can populate a datagrid with the rows from a table. XAML:
<DataGrid Name="dataGridxxx" ItemsSource="{Binding}" AutoGenerateColumns="True" Height="279" AutoGeneratingColumn="dataGridxxx_AutoGeneratingColumn">
C#:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
string MyConString =
"SERVER=xxx;" +
"DATABASE=xxx;" +
"UID=xxx;" +
"PASSWORD=xxx;";
string sql = "SELECT * FROM xxx ORDER BY lastName";
using (MySqlConnection connection = new MySqlConnection(MyConString))
{
connection.Open();
using (MySqlCommand cmdSel = new MySqlCommand(sql, connection))
{
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);
da.Fill(dt);
dataGridPatients.DataContext = dt;
}
connection.Close();
}
}
Now I have a “Province” field in the table, and it was made an enum(‘ON’, ‘MB’, ‘SK’, etc.) in MySQL workbench. When I create the data connection in VS, I can see that VS sees it’s an enum type. I thought if the AutoGenerateColumns was set to true, the grid is smart enough to put a combobox with the DB enum values in those Province table cells? That’s not happening. It’s just a plain old text field, with maxchars of 2…
Any ideas? Do I have to create a new DataSet in my project to create C# classes from my database schema?
The correct answer is in H.B.’s referenced post… “don’t use them”. Seeing as I’m new to databases as well, I didn’t know the proper and standard way of handling enums is by using a reference table. Snagged the link from a few clicks away: Why MySQL enums are evil