Problem in displaying data in WPF datagrid

Apr 7, 2010 at 1:58 PM

Hi,

 I want to display data from oracleDB in WPF datgrid by manually providing the column names.When  AutoGenerateColumns= true the data is displayed

with column names as given in the database but when AutoGenerateColumns= false only column header names are shown with no data displayed.

The following is the code...Can anyone help me with this issue.

XAML:

<Grid Name="MyGrid" >
        <my:DataGrid AutoGenerateColumns ="False" ItemsSource="{Binding}" Margin="0,0,0,162" Name="dataGrid1">
            <my:DataGrid.Columns>
                <my:DataGridTextColumn Header="Name" Binding="{ Binding Path= last_name}" ></my:DataGridTextColumn>
                <my:DataGridTextColumn Header="Date" Binding="{ Binding Path= hire_date}" ></my:DataGridTextColumn>
            </my:DataGrid.Columns>
        </my:DataGrid>
    </Grid>

 

<Grid Name="MyGrid" >

        <my:DataGrid AutoGenerateColumns ="False" ItemsSource="{Binding}" Margin="0,0,0,162" Name="dataGrid1">

            <my:DataGrid.Columns>

                <my:DataGridTextColumn Header="Name" Binding="{ Binding Path= last_name}" ></my:DataGridTextColumn>

                <my:DataGridTextColumn Header="Date" Binding="{ Binding Path= hire_date}" ></my:DataGridTextColumn>

            </my:DataGrid.Columns>

        </my:DataGrid>

    </Grid>

C# .Net Code

 

   private OracleConnection conn = new OracleConnection();      

   private OracleDataAdapter da;

   private DataSet ds;

   private void OpenOracleConnection()

   {

        conn.ConnectionString = "User ID = hr; Password=hr;";

       conn.Open();

    }

  private void GridDisplay(string s )

  {                

        da = new OracleDataAdapter(s,conn);                

        ds = new DataSet();                

        da.Fill(ds);

        dataGrid1.DataContext = ds.Tables[0].DefaultView;                         

   }

   private void OnWindowload(object sender, RoutedEventArgs e)

   {

       OpenOracleConnection();

       string sql = "Select last_name,hire_date from employees";

       GridDisplay(sql);

    }