Datagrid for Windows Forms does not automatically drop down

M

MarkCFC

My project consists of one form and one standard microsoft datagrid.

In code and not by binding, I create a sqlconnection, sqlAdapter and dataset. When the form is displayed I have to click on the datagrid to display the result of my query. I cannot get the datagrid to automatically show the result on the form. In other words you need to click the grid twice to display the results.

Is this how the grid works? Surely not. Can somebody help?

My code is?

In the Form_Load event place the following:

SqlConnection mySqlConnection = new SqlConnection(data source=<servername>;persist security info=False;initial catalog=Northwind");

SqlDataAdapter mySqlAdapter = new SqlDataAdapter("SELECT * FROM EMPLOYEES",mySqlConnection);

DataSet myDataSet = new DataSet();
mySqlAdapter.Fill(myDataSet,"EMPLOYEES");
dataGrid1.DataSource = myDataSet;


thanks
Mark
 
G

Guest

Use the Table as the datasource instead of the Dataset.

dataGrid1.DataSource = MyDataSet.Tables["EMPLOYEES"]

/Tobbe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top