The datasource property of the datagrid is set in the designer.
I expanded the form with a third button for switching the Datasource:
private void button3_Click(object sender, EventArgs e)
{
if (dataGrid1.DataSource == dataSet1)
{
dataGrid1.DataSource = dataSet1.Tables["NewTable"];
}
else
dataGrid1.DataSource = dataSet1;
}
If the datasource references directly to the datatable, data is shown. If it
references to the dataset, the tree is shown with "NewTable" but NewTable has
0 (1 row with NULL values) rows.
Why is this?? Plz help!!!
"Paul Clement" wrote:
> On Tue, 20 Dec 2005 02:27:04 -0800, mspzzz <(E-Mail Removed)> wrote:
>
> ¤ I am using a DataGrid with a dataset and the
> ¤ OracleDataAdapter.Fill(dataset,"Tablename") method. All is fine: a table is
> ¤ created and mapped to the dataset and data is shown in the datagrid.
> ¤
> ¤ When I clear the table, dispose it and remove it from the dataset, and then
> ¤ reload the same table with the fill statement, the datagrid shows (NULL)
> ¤ although the debug output shows that there is a table mapped to the dataset
> ¤ with populated rows. Although when I try to remove it again by index from the
> ¤ DataSet, I get a NullPointerException - but the Table is present!
> ¤
> ¤ What am I missing? If anyone can verify this strange behaviour?
> ¤
> ¤ Test-Code is like this:
> ¤
> ¤ namespace TestDsLoadClear
> ¤ {
> ¤ public partial class Form1 : Form
> ¤ {
> ¤ public Form1()
> ¤ {
> ¤ InitializeComponent();
> ¤ }
> ¤
> ¤ /// <summary>
> ¤ /// DeleteButton
> ¤ /// </summary>
> ¤ /// <param name="sender"></param>
> ¤ /// <param name="e"></param>
> ¤ private void button2_Click(object sender, EventArgs e)
> ¤ {
> ¤ dataSet1.Tables[0].Clear();
> ¤ dataSet1.Tables[0].Dispose();
> ¤ dataSet1.Tables.RemoveAt(0);
> ¤
> ¤ button2.Enabled = false;
> ¤ button1.Enabled = true;
> ¤ }
> ¤
> ¤ /// <summary>
> ¤ /// LoadButton
> ¤ /// </summary>
> ¤ /// <param name="sender"></param>
> ¤ /// <param name="e"></param>
> ¤ private void button1_Click(object sender, EventArgs e)
> ¤ {
> ¤ oracleDataAdapter1.Fill(dataSet1, "NewTable");
> ¤ button1.Enabled = false;
> ¤ button2.Enabled = true;
> ¤ }
> ¤ }
> ¤ }
>
> I don't believe the DataGrid will display any data until you set the DataSource property to the new
> DataTable.
>
>
> Paul
> ~~~~
> Microsoft MVP (Visual Basic)
>
|