The reason why I am having a hard time populating this table is because the table get’s created dynamically:
MySql.Data.MySqlClient.MySqlDataReader selection = mySql.QuerySelect(textBox1.Text); //textBox1.Text containts the text of the query to be executed
DataTable table = new DataTable(); // create table to hold results
// depending on the query construct the needed columns
for (int i = 0; i < selection.FieldCount; i++)
{
table.Columns.Add("Column " + i);
}
// while there are rows insert them
while (selection.Read())
{
object[] o = new object[selection.FieldCount];
for(int j=0; j<selection.FieldCount; j++)
{
o[j] = selection[j].ToString();
}
table.Rows.Add(o);
}
ok so far after this point my table is constructed.
now my problem is how can I display that table so that user can see the results.
here are the things I have tried:
with a datagrid:
<DataGrid AutoGenerateColumns="False" Margin="73,264,17,12" Name="dataGrid1" ItemsSource="{Binding}" />
code behind:
dataGrid1.DataContext = table.DefaultView;
that does not display the results. the rows get populated and rows two but with no content…
with ListView
<ListView Height="72" Margin="78,253,17,0" Name="listView1" VerticalAlignment="Top" ItemsSource="{Binding}" />
code behind:
listView1.DataContext = table.DataSet;
listView1.DataContext = table.DefaultView;

note the correct number of rows are displayed but with the wrong content.
with a ListBox
similar technique….
You want columns in your grid, so you probably don’t want
AutoGenerateColumns="False".To use a
<ListView>, you’ll need to make columns yourself in a<GridView>.To use a
<ListBox>, setDisplayTemplateto a<DataTemplate>containing UI for the listboxes.