datagrid

  • Thread starter Thread starter Dino L.
  • Start date Start date
D

Dino L.

Hi guys
I fill my datagrid like this
---
komanda.CommandText ="SELECT IDKlasa AS ID, IDslova, IDbroj, Naziv, JM,
Normativ FROM Klase WHERE IDslova LIKE('" + cmbIDslova.SelectedItem +
"%') AND Naziv LIKE('%" + txtZavod.Text + "%')";
// MessageBox.Show(komanda.CommandText.ToString());
adapter.SelectCommand =komanda;
adapter.FillSchema (ds,SchemaType.Source,"Klase");
adapter.Fill (ds,"Klase");
dataGrid1.SetDataBinding(ds,"Klase");
 
hi


To set a column width, your datagrid must be using a non-null
DataGridTableStyle. Once this is in place, you can set the column width by
first getting the tablestyle and then using that object to obtain a column
style with which you can set the width. Here are some code snippets showing
how you might do this.

//.... make sure your DataGrid is using a tablestyle

dataGrid1.DataSource = _dataSet.Tables["customers"];

DataGridTableStyle dgts = new DataGridTableStyle();

dgts.MappingName = "customers";

dataGrid1.TableStyles.Add(dgts);



//......



//method to set a column with by colnumber

public void SetColWidth(DataGridTableStyle tableStyle, int colNum, int width)

{

try

{

tableStyle.GridColumnStyles[colNum].Width = width;

tableStyle.DataGrid.Refresh();

}

catch{} //empty catch .. do nothing

}



//....



// here is how you might call this method



private void button1_Click(object sender, System.EventArgs e)

{

DataGridTableStyle tableStyle = dataGrid1.TableStyles["customers"];

SetColWidth(tableStyle, 1, 200);

}



regards
ansil
 
tnx
this works really good

Ansil said:
hi


To set a column width, your datagrid must be using a non-null
DataGridTableStyle. Once this is in place, you can set the column width by
first getting the tablestyle and then using that object to obtain a column
style with which you can set the width. Here are some code snippets showing
how you might do this.

//.... make sure your DataGrid is using a tablestyle

dataGrid1.DataSource = _dataSet.Tables["customers"];

DataGridTableStyle dgts = new DataGridTableStyle();

dgts.MappingName = "customers";

dataGrid1.TableStyles.Add(dgts);



//......



//method to set a column with by colnumber

public void SetColWidth(DataGridTableStyle tableStyle, int colNum, int width)

{

try

{

tableStyle.GridColumnStyles[colNum].Width = width;

tableStyle.DataGrid.Refresh();

}

catch{} //empty catch .. do nothing

}



//....



// here is how you might call this method



private void button1_Click(object sender, System.EventArgs e)

{

DataGridTableStyle tableStyle = dataGrid1.TableStyles["customers"];

SetColWidth(tableStyle, 1, 200);

}



regards
ansil

:

Hi guys
I fill my datagrid like this
---
komanda.CommandText ="SELECT IDKlasa AS ID, IDslova, IDbroj, Naziv, JM,
Normativ FROM Klase WHERE IDslova LIKE('" + cmbIDslova.SelectedItem +
"%') AND Naziv LIKE('%" + txtZavod.Text + "%')";
// MessageBox.Show(komanda.CommandText.ToString());
adapter.SelectCommand =komanda;
adapter.FillSchema (ds,SchemaType.Source,"Klase");
adapter.Fill (ds,"Klase");
dataGrid1.SetDataBinding(ds,"Klase");
 
Back
Top