Hi,
I have a DataGridView which doesn't show the data after setting the DataSource to a DataSet. The way I am doing is like this.
1. I have a class "GridData" which derives from "System.Windows.Forms.Form". In this class I have made the DataGridView control a public member. See the code below.
2. I have another form "Form1 " with a button. When the button is clicked, I get the dataset, create "GridData" form and set the DataGridView DataSource property. Finally I call Show for the GridData form. Please see the code below.
public class GridData : System.Windows.Forms.Form
{
public System.Windows.Forms.DataGridView dataGridView1;
public GridData()
{
this.InitializeComponent();
}
public void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(37, 43);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(494, 178);
this.dataGridView1.TabIndex = 0;
//
// GridData
//
this.ClientSize = new System.Drawing.Size(593, 311);
this.Controls.Add(this.dataGridView1);
this.Name = "GridData";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
}
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
GridData form = new GridData();
DataSourceDA da = new DataSourceDA();
DataSource ds = da.GetDataSource("TitleAuthors");
BaseDataGateway dataGateway = DataGatewayFactory.GetDataGateway(ds);
DataSet dataset = (DataSet)dataGateway.GetData(ds); //has only one table in the dataset
form.dataGridView1.AutoGenerateColumns = true;
form.dataGridView1.DataSource = dataset;
form.Show();
}
}
What am I doing wrong?.
Ravi