Problem populating DataGridView
Hi there
I have a problem. Im populating a datagridview in runtime.
Connecting my datasource to the DataGridView results in a Datagrid with all the collums in the datasource. But i dont want all collums in the data grid. How can i make this happen. Because the other values i want to bind to labels and txtboxes.
Here is my code
private void LoadData()
{
SqlConnectionStringBuilder bld = new SqlConnectionStringBuilder();
bld["server"] = ".\\sqlexpress";
bld["AttachDBFileName"] = "D:\\FolktaleDB.mdf";
bld["user Id"] = "sa";
bld["Integrated security"] = "sspi";
string connectionString = bld.ConnectionString;
conn = new SqlConnection(connectionString);
qry = "SELECT AddressId, Address1, Address2,
City, State, ZipCode, Country
FROM Address";
da = new SqlDataAdapter(qry, conn);
conn.Open();
ds = new DataSet();
da.Fill(ds, "Address");
bsource.DataSource = ds.Tables["Address"];
dgvBlock.DataSource = bsource;
richTextBox1.DataBindings.Add("Text", bsource, "AddressId", true);
conn.Close();
}
I only want the 2 fields in the datagrid and the others binded to the labels and txtboxes.
I hope some one can help me.
Kind regards
MacDevv
|