Bonjour à tous,
je souhaite importer un fichier csv dans un datagridview, mais avec les particularités suivantes:
La première ligne de mon fichier csv doit correspondre aux entêtes du datagridview
Je ne souhaite que garder les colonnes 1,2,16,17,20,21,24,25,26 les autres doivent être masquée.
Je cherche une solution simple.
Pour l'instant j'arrive à importer mes données dans le datagridview mais pas à renommer les colonnes.
Voici la première ligne de mon fichier CSV:
Matricule;Nom;Prenom;Nom Naissance;Pseudo de connexion;Mot de passe de connexion;Civilité;Téléphone Perso;Téléphone Pro;Email Perso;Email Pro;Préférence envoi courier;Adresse;Adresse suite;Code Postal;Ville;Service;Statut;Contrat;Date de naissance;Date d'entrée;Date de sortie;Situation familiale;Matricule conjoint dans entreprise;Coefficient 2014;Coefficient 2015;Coefficient 2016;Banque;Titulaire;IBAN;BIC;Autorisation de prélèvement;N° de compte
Voici mon code:
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
| Dim TextFileReader As New FileIO.TextFieldParser(selectedFile)
TextFileReader.TextFieldType = FileIO.FieldType.Delimited
TextFileReader.SetDelimiters(";")
Dim TextFileTable As DataTable = Nothing
Dim Column As DataColumn
Dim Row As DataRow
Dim UpperBound As Int32
Dim ColumnCount As Int32
Dim CurrentRow As String()
While Not TextFileReader.EndOfData
Try
CurrentRow = TextFileReader.ReadFields()
If Not CurrentRow Is Nothing Then
''# Check if DataTable has been created
If TextFileTable Is Nothing Then
TextFileTable = New DataTable("TextFileTable")
''# Get number of columns
UpperBound = CurrentRow.GetUpperBound(0)
''# Create new DataTable
For ColumnCount = 0 To UpperBound
Column = New DataColumn()
Column.DataType = System.Type.GetType("System.String")
'tutu = CurrentRow(ColumnCount).ToString
' Column.ColumnName = CurrentRow(ColumnCount).ToString
Column.ColumnName = "Column" & ColumnCount
Column.Caption = CurrentRow(ColumnCount).ToString
Column.ReadOnly = True
Column.Unique = False
TextFileTable.Columns.Add(Column)
Next
End If
'ajout des données
Row = TextFileTable.NewRow
For ColumnCount = 0 To UpperBound
Row("Column" & ColumnCount) = CurrentRow(ColumnCount).ToString
Next
TextFileTable.Rows.Add(Row)
End If |
J'ai cherché un peux partout mais je ne trouve pas la solution, si quelqu'un peux m'aider...
Merci d'avance
Partager