Ahmed Mohammed Ahmed Mohammed - 4 months ago 11
MySQL Question

Binding datagrid filled from MySQL

i have that code in my desktop application that fill the datagrid from mysql database

var mA = new MySql.Data.MySqlClient.MySqlDataAdapter("SELECT * FROM items", DataHolder.MySqlConnection);
var mT = new System.Data.DataTable();
mA.Fill(mT);
dataGrid.ItemsSource = mT.DefaultView;


but i can't figure out how to bind it to change certain cells in certain column to change it's background color when it's equl to certain values.

in that case there isn't no columns to bind in the datagrid until the code is executed what i am asking is "how to make it work with that"?!

Answer

i know how to change the background color for datagrid that already have columns in it but in that case there isn't no columns to bind in the datagrid until the code is executed

This implies that you are using the auto generated columns. You just need to hook AutoGeneratingColumn or AutoGeneratedColumns, which give you access to the new columns in the event args, which you then can style accordingly (would recommend defining styles in XAML resources somewhere).