IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

[C#] Largeur de colonne et de ligne dans un DataGrid


Sujet :

Windows Forms

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    266
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 266
    Points : 135
    Points
    135
    Par défaut [C#] Largeur de colonne et de ligne dans un DataGrid
    Bonjour

    j'ai créer un datatable ou j'y rentrer directement mes données sans passer par une base de données.
    Ce datatable je le mets dans un dataset pour me permettre de configurer mon Datagrid avec mon Dataset.

    Mon souci est de donner une largueur de colone de 30 px et une largeur de
    ligne de 15 px.

    j'ai fait :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    dataGrid1.TableStyles.Clear();
    dataGrid1.TableStyles.Add(tableStyle);
    dataGrid1.DataSource = _dataSet.Tables["MyTable"];
    dataGrid1.PreferredColumnWidth=30;
    dataGrid1.PreferredRowHeight=15;
    mais rien a faire tout marche sauf la taille de mes colone et de mes lignes
    qui reste a la meme taille quoi que je mette.


    merci de votre aide

  2. #2
    En attente de confirmation mail

    Profil pro
    Inscrit en
    Février 2003
    Messages
    126
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France

    Informations forums :
    Inscription : Février 2003
    Messages : 126
    Points : 127
    Points
    127
    Par défaut
    Pour utiliser la mise en forme de ton datagrid utilises tu un DataGridTableStyle ? Ci après un extrait de code qui marche très bien chez moi.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
     
    			DataGridTableStyle ts1 = new DataGridTableStyle();
    			ts1.MappingName = "Table_Item";
    			ts1.AlternatingBackColor = Color.LightGray;
     
    			//EAN
    			DataGridColumnStyle EAN = new DataGridTextBoxColumn();
    			EAN.MappingName = "Code Ean";
    			EAN.HeaderText = "Code Ean Article";
    			EAN.Width = 110;
    			EAN.ReadOnly = true;
    			//Code Vegas
    			DataGridColumnStyle CODEVEGAS = new DataGridTextBoxColumn();
    			CODEVEGAS.MappingName = "Code Vegas";
    			CODEVEGAS.HeaderText = "Code Vegas";
    			CODEVEGAS.Width = 80;
    			CODEVEGAS.Alignment =  HorizontalAlignment.Center;
                //Désignation
    			DataGridColumnStyle DESIGNATION = new DataGridTextBoxColumn();
    			DESIGNATION.MappingName = "Désignation";
    			DESIGNATION.HeaderText = "Désignation / Nom Complet";
    			DESIGNATION.Width = 200;
    			//Code Sous Famille
    			DataGridColumnStyle CSF = new DataGridTextBoxColumn();
    			CSF.MappingName = "Code Sous Famille";
    			CSF.HeaderText = "Code Sous Famille";
    			CSF.Width = 120;
    			CSF.Alignment =  HorizontalAlignment.Center;
    			//Sous Famille
    			DataGridColumnStyle SF = new DataGridTextBoxColumn();
    			SF.MappingName = "Sous Famille";
    			SF.HeaderText = "Sous Famille";
    			SF.Width = 200;
    			SF.Alignment =  HorizontalAlignment.Center;
    			//	Famille
    			DataGridColumnStyle FAM = new DataGridTextBoxColumn();
    			FAM.MappingName = "Famille";
    			FAM.HeaderText = "Famille";
    			FAM.Width = 200;
    			FAM.Alignment =  HorizontalAlignment.Center;
    			//		Modèle
    			DataGridColumnStyle MODELE = new DataGridTextBoxColumn();
    			MODELE.MappingName = "Modèle";
    			MODELE.HeaderText = "Modèle";
    			MODELE.Width = 100;
    			MODELE.Alignment =  HorizontalAlignment.Center;
    			//[Critère de Distribution]
    			DataGridColumnStyle CDD = new DataGridTextBoxColumn();
    			CDD.MappingName = "Critère de Distribution";
    			CDD.HeaderText = "Distribution";
    			CDD.Width = 100;
    			CDD.Alignment =  HorizontalAlignment.Center;
    			//[Segmentation Produit]
    			DataGridColumnStyle SEGMT = new DataGridTextBoxColumn();
    			SEGMT.MappingName = "Segmentation Produit";
    			SEGMT.HeaderText = "Segm° Produit";
    			SEGMT.Width = 110;
    			SEGMT.Alignment =  HorizontalAlignment.Center;
     
    			ts1.GridColumnStyles.Add(EAN);
    			ts1.GridColumnStyles.Add(CODEVEGAS);
    			ts1.GridColumnStyles.Add(DESIGNATION);
    			ts1.GridColumnStyles.Add(CSF);
    			ts1.GridColumnStyles.Add(SF);
    			ts1.GridColumnStyles.Add(FAM);
    			ts1.GridColumnStyles.Add(MODELE);
    			ts1.GridColumnStyles.Add(CDD);
    			ts1.GridColumnStyles.Add(SEGMT);
     
    			dataGrid1.TableStyles.Add(ts1);

  3. #3
    Expert éminent
    Avatar de bidou
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2002
    Messages
    3 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Transports

    Informations forums :
    Inscription : Mai 2002
    Messages : 3 055
    Points : 7 962
    Points
    7 962
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    DataGridTableStyle ts = new DataGridTableStyle(); 
    this.dataGrid1.TableStyles.Add(ts);
    ts.MappingName=MaTable.TableName;
    this.dataGrid1.DataSource=MaTable;			
    this.dataGrid1.TableStyles[0].GridColumnStyles[0].Width=100;
    this.dataGrid1.TableStyles[0].GridColumnStyles[1].Width=200;

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    266
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 266
    Points : 135
    Points
    135
    Par défaut
    Citation Envoyé par bidou
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    DataGridTableStyle ts = new DataGridTableStyle(); 
    this.dataGrid1.TableStyles.Add(ts);
    ts.MappingName=MaTable.TableName;
    this.dataGrid1.DataSource=MaTable;			
    this.dataGrid1.TableStyles[0].GridColumnStyles[0].Width=100;
    this.dataGrid1.TableStyles[0].GridColumnStyles[1].Width=200;
    Merci bien c'est la meilleur facon j'avais deja essayer mais avant le data source et comme apres je recoloriais certaine cellule ca me remettais automatiquement les dimention par defaut

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    			dataGrid1.DataSource = _dataSet.Tables["MyTable"];
    			AddCellFormattingColumnStyles(this.dataGrid1, new FormatCellEventHandler(FormatGridCells));
    			this.dataGrid1.TableStyles[0].GridColumnStyles[0].Width=70;
    			this.dataGrid1.TableStyles[0].GridColumnStyles[1].Width=70;
    merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. total colonne et total ligne dans une requete croisée
    Par maamer dans le forum Requêtes et SQL.
    Réponses: 6
    Dernier message: 11/06/2018, 12h37
  2. [WD17] Calcul résultat de 2 colonne pour chaque ligne dans une table
    Par magicien33 dans le forum WinDev
    Réponses: 5
    Dernier message: 09/09/2013, 11h28
  3. [AC-2007] En-tête de colonne sur plusieurs lignes dans une list box
    Par Rémi GAUDINAT dans le forum IHM
    Réponses: 2
    Dernier message: 25/10/2010, 11h52
  4. Réponses: 18
    Dernier message: 05/08/2008, 10h44
  5. JTable Largeur de colonne + retour à la ligne
    Par JuTs dans le forum Composants
    Réponses: 7
    Dernier message: 02/02/2006, 23h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo