Peter,
The following code results in nothing appearing in the DataGridView:
BindingSource bs = new BindingSource();
private void initDataGridView(DataGridView dgv)
{
// dsForDGV is a datset object on the form
dsForDGV.Tables[0].Rows.Add("abc");
dsForDGV.Tables[0].Rows[0][0] = 1234;
bs.DataSource = dsForDGV;
bs.DataMember = dsForDGV.Tables[0].TableName;
dgv.DataSource = bs;
dgv.Refresh();
}
What am I doing wrong? When the form opens the DataGridView control has
the correct number of rows and columns, but they are all blank.
Bill
Peter wrote:
> A DataSet is just a representation of an in-memory data cache. The data
> could come from anywhere. DataSet supports XML files directly and usually
> DataAdapters are uses to fill the DataSet via a database connection. You can
> manually create a DataSet by adding DataTable objects to the
> DataTableCollection property "Tables". For an example of creating a DataSet
> without using an XML file or populating via a database connection see
> http://msdn2.microsoft.com/en-us/library/aeskbwf7.aspx
>
> Binding that DataSet to the DataGridView would be the same as if the DataSet
> was populate via a database connection and a DataAdapter.
>
> --
> Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
> http://www.peterRitchie.com/blog/
> Microsoft MVP, Visual Developer - Visual C#
>
>
> "bill" wrote:
>
> > All,
> >
> > Where can I find some sample code for binding a DataGridView to a
> > dataset without having the dataset attached to a database?
> >
> > TIA,
> >
> > Bill
> >
> >