Binding to Datagrid
Most simpler way to bind your data values to datagridview in Windows Application.
Just need to call the method and your datagrid is bound.
public void bindgrid()
{
try
{
DataSet ds = new DataSet();
string strconnection = "Dsn=test; uid=root;";
OdbcConnection Conn = new OdbcConnection(strconnection);
DataTable dt;
OdbcDataAdapter ad;
ds = new DataSet();
ad = new OdbcDataAdapter("select * from sample", Conn);
ad.Fill(ds, "sample");
dt = ds.Tables[0];
this.dataGridView1.DataSource = dt.DefaultView;
this.dataGridView1.DataBindings.Control.CreateControl();
}
catch
{
}
}
Also if u need to set the column width programmatically then u need to add
DataGridTableStyle tabStyle = new DataGridTableStyle();
tabStyle.MappingName = dt.TableName;
dtBDGrid.TableStyles.Add(tabStyle);
tabStyle.GridColumnStyles[0].Width = 125;
hi,
For Width you can directly give
DataGridView1.Columns[0].Width=125;
then why to give for DataGridTableStyle Class
And as your are selecting data from database then all the columns are of type textboxes then why to call databingings method
can u plz send me the exact definition of the code