Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
private void button2_Click(object sender, RoutedEventArgs e)
       {

           connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Project/Book.accdb";
           connection = new OleDbConnection(connectionstring);
           sql = "Select*from Authors";

           try
           {
               connection.Open();
               oledbAdapter = new OleDbDataAdapter(sql, connection);
               oledbAdapter.Fill(dt);

               // dataGrid1.DataContext = dt;

           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.ToString());
           }

           DataGrid dg2 = new DataGrid();
           dg2.Height = 200;
           dg2.Width = 200;
           dg2.AutoGenerateColumns = true;
           dg2.AlternatingRowBackground = Brushes.Black;
           dg2.Background = Brushes.Red;
           dg2.BorderBrush = Brushes.Pink;
           dg2.HorizontalGridLinesBrush = Brushes.Black;
           dg2.DataContext = dt;
           stackPanel1.Children.Add(dg2);

       }


it is expected that the code should display the DataGrid with its underlying Data. but it is not happening.
it gives only a Red back ground. no data at all .No Grid lines also. I am missing something very seriously. please i request somebody help

Regards

Iqbal
NB: I am just started learning
Posted
Comments
Shahin Khorshidnia 18-Jan-12 18:34pm    
I don't see any binding.

1 solution

after

C#
stackPanel1.Children.Add(dg2);


use

C#
dg2.ItemsSource = Your Source


I think it can help.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900