Vb.net datagrid

roxane101 Messages postés 28 Date d'inscription vendredi 12 mai 2006 Statut Membre Dernière intervention 26 décembre 2006 - 28 mai 2006 à 14:24
roxane101 Messages postés 28 Date d'inscription vendredi 12 mai 2006 Statut Membre Dernière intervention 26 décembre 2006 - 28 mai 2006 à 22:58
Bonjour
je veux changer la largeur d'une colonne de datagrid.
j'ai trouvé une methode : grid.PreferredColumnWidth=valeur.
mais cette methode s'applique sur toutes les colonnes et moi je
veux modifier la largeur d'une seule colonne.
Merci pour votre aide.

3 réponses

nhervagault Messages postés 6063 Date d'inscription dimanche 13 avril 2003 Statut Membre Dernière intervention 15 juillet 2011 37
28 mai 2006 à 22:05
Salut,

regardes sur le site
http://www.syncfusion.com/faq/windowsforms/default.aspx

Voila la reponse plus precise

/.... 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);
}

Il te reste plus qu'a convertir en VB.Net
0
nhervagault Messages postés 6063 Date d'inscription dimanche 13 avril 2003 Statut Membre Dernière intervention 15 juillet 2011 37
28 mai 2006 à 22:05
Salut,

regardes sur le site
http://www.syncfusion.com/faq/windowsforms/default.aspx

Voila la reponse plus precise

/.... 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);
}

Il te reste plus qu'a convertir en VB.Net
0
roxane101 Messages postés 28 Date d'inscription vendredi 12 mai 2006 Statut Membre Dernière intervention 26 décembre 2006
28 mai 2006 à 22:58
Merci :)
0
Rejoignez-nous