Bonjour,
J'arrive à coloriser (background et font) les lignes de mon DataGrid si besoin mais, elles ne sont plus en couleur après la réouverture de l'application. Je vous remercie pour votre aide.
J'enregistre mes couleurs :
Code vb : 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 Private Sub SaveColorAndFont(rowIndex As Integer, backColor As String, foreColor As String) Dim lines As New List(Of String) If File.Exists("couleurs.ini") Then lines = File.ReadAllLines("couleurs.ini").ToList() End If ' Update if exists Dim updated = False For i As Integer = 0 To lines.Count - 1 Dim parts = lines(i).Split(";"c) If parts(0) = rowIndex.ToString() Then parts(1) = backColor parts(2) = foreColor lines(i) = String.Join(";", parts) updated = True Exit For End If Next ' Add new if not updated If Not updated Then lines.Add($"{rowIndex};{backColor};{foreColor}") End If File.WriteAllLines("couleurs.ini", lines) End Sub
Dans couleurs.ini cela enregistre bien une couleur de fond et de police à ma 3ème ligne :
2;MediumSeaGreen;White:
Je charge les couleurs au démarrage :
Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 Private Sub LoadColorAndFontConfigurations() If File.Exists("couleurs.ini") Then Dim lines = File.ReadAllLines("couleurs.ini") For Each line As String In lines Dim parts = line.Split(";"c) Dim rowIndex = Integer.Parse(parts(0)) Dim backColor = parts(1) Dim foreColor = parts(2) If rowIndex < DataGridView1.Rows.Count Then DataGridView1.Rows(rowIndex).DefaultCellStyle.BackColor = ColorTranslator.FromHtml(backColor) DataGridView1.Rows(rowIndex).DefaultCellStyle.ForeColor = ColorTranslator.FromHtml(foreColor) End If Next End If End Sub
Dans Form_Load :
Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load InitialiserDataGridView() ChargerDonneesExistantes() LoadColorAndFontConfigurations()
![]()
Partager