Hello,

J'en perds mon latin...

Voici un petit bout de code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
        If promo.DTO.DetailsDemo.Count > 0 OrElse promo.DTO.DetailsOwn.Count > 0 Then
            If MessageBox.Show(String.Format(messages.GetText("msgDeletePromo"), vbCrLf),
                               messages.GetText("msgQuestion"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                promo.Delete()
            End If
        Else
            If MessageBox.Show(messages.GetText("msgDeleteLine"), messages.GetText("msgQuestion"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                promo.Delete()
            End If
        End If
C'est un bout de code d'une application pour gérer les promotions d'un magasin...

Quelques explications :
Ligne 1 : On vérifie si des choses ont déjà été encodé pour la promo
Ligne 2 et 3 : On affiche une demande de confirmation pour la suppression en signalant que ce qui a déjà été encodé sera perdu (les messages.GetText("clef") vont chercher le texte à afficher dans la bonne langue)
Ligne 4 : On supprime
Ligne 7 : On affiche une demande standard de confirmation pour la suppression (rien n'est encore encodé donc pas besoin d'avertissement particulier)
Ligne 8 : On supprime

Le truc bizarre, c'est que lorsqu'on arrive sur les lignes 4 ou 8, le contenu de l'objet promo change pour devenir la première promo affichée dans la grille... Il y a bien un event RowEnter sur la grille (datagridview) mais je fais pareil dans toutes mes applications et c'est la première fois que j'ai un comportement pareil... (ou alors j'ai le bug partout et personne ne m'a jamais rien dit )

Pour info, le code de l'event RowEnter :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
    Private Sub dgvPromo_RowEnter(sender As Object, e As DataGridViewCellEventArgs) Handles dgvPromo.RowEnter
        If e.RowIndex > -1 Then
            promo = promos.GetById(CInt(dgvPromo.Rows(e.RowIndex).Cells("dgvcId").Value))
        Else
            promo = Nothing
        End If
 
        EnablingMenuItem((Not IsNothing(promo)))
    End Sub
Rien de compliqué donc. Que du standard/basic...

Mais de toute façon, en debug step by step, on ne passe pas dans l'event. Donc aucune raison que le contenu de promo change...
J'ai fait une recherche sur le texte "promo = " histoire de trouver tous les endroits où j'affecte quelque chose dans mon objet et c'est le seul endroit...

Quelqu'un aurait une idée de ce qu'il se passe ? Dois-je faire venir un exorciste ?

N.B. : Si nécessaire, je peux montrer plus de code.

N.B.2 : Histoire de, voici le code des classes Promo et Promos...
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
Public Class Promo
    Public Property DTO As PROMO_DTO.Promo
 
    Public Sub New(dto As PROMO_DTO.Promo)
        Me.DTO = dto
    End Sub
 
    Public Sub GetStores()
        Me.DTO.Stores = PROMO_DAL.Promo.GetStores(Me.DTO.Id)
    End Sub
 
    Public Sub GetTargets()
        Me.DTO.Targets = PROMO_DAL.Promo.GetTargets(Me.DTO.Id)
    End Sub
 
    Public Sub GetBuyingDepts()
        Me.DTO.BuyDepts = PROMO_DAL.Promo.getBuyDepts(Me.DTO.Id)
    End Sub
 
    Public Sub GetDays(language As Byte)
        Me.DTO.Days = PROMO_DAL.Promo.GetDays(Me.DTO.Id, language)
    End Sub
 
    Public Sub GetDetailsDemo(withProduct As Boolean, Optional ba_id As Byte? = Nothing)
        Me.DTO.DetailsDemo = PROMO_DAL.PromoDetail.GetPromoDetailDemo(Me.DTO.Id, ba_id)
        If withProduct Then
            GetDemoProducts()
        End If
    End Sub
 
    Public Sub GetDetailsOwn(withProduct As Boolean, withSeason As Boolean, Optional ba_id As Byte? = Nothing)
        Me.DTO.DetailsOwn = PROMO_DAL.PromoDetail.GetPromoDetailOwn(Me.DTO.Id, ba_id)
        If withProduct Then
            GetOwnProducts()
        End If
        If withSeason Then
            GetOwnSeasons()
        End If
    End Sub
 
    Public Sub GetDetailsDepartment(withProduct As Boolean, withSeason As Boolean, Optional ba_id As Byte? = Nothing)
        Me.DTO.DetailsDepartment = PROMO_DAL.PromoDetail.GetPromoDetailsDepartment(Me.DTO.Id, ba_id)
        If withProduct Then
            GetDepartmentProducts()
        End If
        If withSeason Then
            GetDepartmentSeasons()
        End If
    End Sub
 
    Public Sub GetDepartmentProducts()
        For Each detail As PROMO_DTO.PromoDetailDepartment In Me.DTO.DetailsDepartment
            detail.Products = PROMO_DAL.Product.GetDeptProductOut(detail.Id)
        Next
    End Sub
 
    Public Sub GetDepartmentSeasons()
        For Each detail As PROMO_DTO.PromoDetailDepartment In Me.DTO.DetailsDepartment
            detail.Seasons = PROMO_DAL.Season.GetSeasons(Nothing, detail.Id)
            'detail.SeasonsRange = CreateSeasonsRanges(detail.Seasons, detail.Department)
        Next
    End Sub
 
    Public Sub GetDemoProducts()
        For Each detail As PROMO_DTO.PromoDetailDemo In Me.DTO.DetailsDemo
            detail.Products = PROMO_DAL.Product.GetDemoProduct(detail.Id)
            detail.ProductsOut = PROMO_DAL.Product.GetDemoProductOut(detail.Id)
        Next
    End Sub
 
    Public Sub GetOwnProducts()
        For Each detail As PROMO_DTO.PromoDetailOwn In Me.DTO.DetailsOwn
            detail.Products = PROMO_DAL.Product.GetOwnProduct(detail.Id)
            detail.ProductsOut = PROMO_DAL.Product.GetOwnProductOut(detail.Id)
        Next
    End Sub
 
    Public Sub GetOwnSeasons()
        For Each detail As PROMO_DTO.PromoDetailOwn In Me.DTO.DetailsOwn
            detail.Seasons = PROMO_DAL.Season.GetSeasons(detail.Id, Nothing)
            'detail.SeasonsRange = CreateSeasonsRanges(detail.Seasons, detail.Department, detail.Brand)
        Next
    End Sub
 
    Public Function GetDemoProducts(detail_id As Integer) As List(Of PROMO_DTO.Product)
        Dim result As List(Of PROMO_DTO.Product) = PROMO_DAL.Product.GetDemoProduct(detail_id)
        If result.Count = 0 Then
            result = PROMO_DAL.Product.GetDemoProductOut(detail_id)
        End If
        Return result
    End Function
 
    Public Function GetOwnProducts(percentage_id As Integer) As List(Of PROMO_DTO.Product)
        Dim result As List(Of PROMO_DTO.Product) = PROMO_DAL.Product.GetOwnProduct(percentage_id)
        If result.Count = 0 Then
            result = PROMO_DAL.Product.GetOwnProductOut(percentage_id)
        End If
        Return result
    End Function
 
    Private Function CreateSeasonsRanges(seasons As List(Of PROMO_DTO.Season), dpt As PROMO_DTO.Department, brand As PROMO_DTO.Brand) As String
        Dim rangeStart As PROMO_DTO.Season = If(seasons.Count > 0, seasons(0), Nothing)
        Dim previous As PROMO_DTO.Season = Nothing
        Dim current As PROMO_DTO.Season = Nothing
        Dim result As String = If(rangeStart Is Nothing, "", rangeStart.Code.ToString("000"))
 
        For Each season As PROMO_DTO.Season In seasons
            previous = current
            current = season
 
            If previous Is Nothing Then
                Continue For
            End If
 
            If current.Code - previous.Code = 1 Then
                Continue For
            ElseIf current.Code - previous.Code > 1 Then
                If IsNothing(dpt) AndAlso IsNothing(brand) Then
                    result &= "->" & previous.Code.ToString("000") & ";" & current.Code.ToString("000")
                Else
                    If Not PROMO_DAL.Season.IsRangePossible(rangeStart.Code, current.Code, dpt.Code, brand.Code) Then
                        result &= "->" & previous.Code.ToString("000") & ";" & current.Code.ToString("000")
                    End If
                End If
            End If
        Next
 
        If Not current Is Nothing Then
            If Not previous Is Nothing Then
                If current.Code - previous.Code = 1 Then
                    result &= "->" & current.Code.ToString("000")
                ElseIf current.Code - previous.Code > 1 Then
                    If IsNothing(dpt) AndAlso IsNothing(brand) Then
                        result &= "->" & current.Code.ToString("000")
                    Else
                        If Not PROMO_DAL.Season.IsRangePossible(rangeStart.Code, current.Code, dpt.Code, brand.Code) Then
                            result &= "->" & previous.Code.ToString("000") & ";" & current.Code.ToString("000")
                        Else
                            result &= "->" & current.Code.ToString("000")
                        End If
                    End If
                End If
            End If
        End If
        Return result
    End Function
 
    Private Function CreateSeasonsRanges(seasons As List(Of PROMO_DTO.Season), dpt As PROMO_DTO.Department) As String
        Dim rangeStart As PROMO_DTO.Season = If(seasons.Count > 0, seasons(0), Nothing)
        Dim previous As PROMO_DTO.Season = Nothing
        Dim current As PROMO_DTO.Season = Nothing
        Dim result As String = If(rangeStart Is Nothing, "", rangeStart.Code.ToString("000"))
 
        For Each season As PROMO_DTO.Season In seasons
            previous = current
            current = season
 
            If previous Is Nothing Then
                Continue For
            End If
 
            If current.Code - previous.Code = 1 Then
                Continue For
            ElseIf current.Code - previous.Code > 1 Then
                If IsNothing(dpt) Then
                    result &= "->" & previous.Code.ToString("000") & ";" & current.Code.ToString("000")
                Else
                    If Not PROMO_DAL.Season.IsRangePossible(rangeStart.Code, current.Code, dpt.Code, New Integer?) Then
                        result &= "->" & previous.Code.ToString("000") & ";" & current.Code.ToString("000")
                    End If
                End If
            End If
        Next
 
        If Not current Is Nothing Then
            If Not previous Is Nothing Then
                If current.Code - previous.Code = 1 Then
                    result &= "->" & current.Code.ToString("000")
                ElseIf current.Code - previous.Code > 1 Then
                    If IsNothing(dpt) Then
                        result &= "->" & current.Code.ToString("000")
                    Else
                        If Not PROMO_DAL.Season.IsRangePossible(rangeStart.Code, current.Code, dpt.Code, New Integer?) Then
                            result &= "->" & previous.Code.ToString("000") & ";" & current.Code.ToString("000")
                        Else
                            result &= "->" & current.Code.ToString("000")
                        End If
                    End If
                End If
            End If
        End If
        Return result
    End Function
 
    'Public Sub LockOrUnlock()
    '    PROMO_DAL.Promo.LockOrUnlockPromo(Me.DTO.Id)
    'End Sub
 
    'Public Sub FlagAsTested()
    '    PROMO_DAL.Promo.FlagAsTested(Me.DTO.Id)
    'End Sub
 
    'Public Sub FlagAsReleased()
    '    PROMO_DAL.Promo.FlagAsReleased(Me.DTO.Id)
    'End Sub
 
    Public Function GetDetailDemoById(dtd_id As Integer) As PromoDetailDemo
        Return New PromoDetailDemo((From d As PROMO_DTO.PromoDetailDemo In DTO.DetailsDemo
                                    Where d.Id = dtd_id
                                    Select d).FirstOrDefault)
    End Function
 
    Public Function GetDetailsDemoByDemo(cont_id As Integer) As PromoDetailsDemo
        Dim result As New PromoDetailsDemo
        For Each detail As PROMO_DTO.PromoDetailDemo In (From d As PROMO_DTO.PromoDetailDemo In Me.DTO.DetailsDemo
                                                         Where d.CodeDemo.Id = cont_id
                                                         Select d).ToList
            result.DTO.Add(detail)
        Next
        Return result
    End Function
 
    Public Function GetDetailOwnById(dto_id As Integer) As PromoDetailOwn
        Return New PromoDetailOwn((From d As PROMO_DTO.PromoDetailOwn In DTO.DetailsOwn
                                   Where d.Id = dto_id
                                   Select d).FirstOrDefault)
    End Function
 
    Public Function GetDetailsOwnByBrandAndDept(bra_id As Integer, dep_id As Short, percentTypeDesc As String) As PromoDetailsOwn
        Dim result As New PromoDetailsOwn
        For Each detail As PROMO_DTO.PromoDetailOwn In (From d As PROMO_DTO.PromoDetailOwn In Me.DTO.DetailsOwn
                                                        Where d.Brand.Id = bra_id And d.Department.Id = dep_id And d.PercentType.Description = percentTypeDesc
                                                        Select d).ToList
            result.DTO.Add(detail)
        Next
        Return result
    End Function
 
    Public Function GetDetailDeptById(ddp_id As Integer) As PromoDetailDepartment
        Return New PromoDetailDepartment((From d As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment
                                          Where d.Id = ddp_id
                                          Select d).FirstOrDefault)
    End Function
 
    Public Function GetDetailsDeptByDept(dep_id As Short) As PromoDetailsDepartment
        Dim result As New PromoDetailsDepartment
        For Each detail As PROMO_DTO.PromoDetailDepartment In (From d As PROMO_DTO.PromoDetailDepartment In Me.DTO.DetailsDepartment
                                                               Where d.Department.Id = dep_id
                                                               Select d).ToList
            result.DTO.Add(detail)
        Next
        Return result
    End Function
 
    Public Function CheckDetailDemo(newDetails As PromoDetailsDemo) As Boolean
        Dim data = (From d As PROMO_DTO.PromoDetailDemo In Me.DTO.DetailsDemo
                    Join d1 As PROMO_DTO.PromoDetailDemo In newDetails.DTO
                    On d.CodeDemo.Code Equals d1.CodeDemo.Code
                    Where d.Id <> d1.Id And d.PercentType.Id <> d1.PercentType.Id
                    Select d1)
 
        If data.ToList.Count > 0 Then
            Throw New EncodingDemoException("multi percentType", data(0).CodeDemo)
        End If
        Return True
    End Function
 
    Public Sub SaveHeader()
        PROMO_DAL.Promo.SaveHeader(Me.DTO)
    End Sub
 
    Public Sub Delete()
        PROMO_DAL.Promo.DeletePromo(Me.DTO.Id)
    End Sub
 
    Public Sub SetAttachment(attach As PROMO_DTO.Attachment)
        If Me.DTO.Attachment.Path.Trim <> "" Then
            IO.File.Delete(Me.DTO.Attachment.Path)
        End If
        Me.DTO.Attachment = attach
        PROMO_DAL.Promo.AttachFileForPromo(Me.DTO.Id, attach)
    End Sub
 
    Public Sub RemoveAttachment()
        If Me.DTO.Attachment.Path.Trim = "" Then
            Exit Sub
        End If
        PROMO_DAL.Promo.DeleteFileForPromo(Me.DTO.Id)
        IO.File.Delete(Me.DTO.Attachment.Path)
        Me.DTO.Attachment = New PROMO_DTO.Attachment("", "", False)
    End Sub
 
    Public Function IsOwnLocked(ba_id As Byte) As Boolean
        Return PROMO_DAL.Promo.IsOwnLocked(Me.DTO.Id, ba_id)
    End Function
 
    Public Function IsDemoLocked(ba_id As Byte) As Boolean
        Return PROMO_DAL.Promo.IsDemoLocked(Me.DTO.Id, ba_id)
    End Function
 
    Public Sub LockUnlockOwn(ba_id As Byte, lock As Boolean)
        If lock = False AndAlso PROMO_DAL.BuyingDepartment.GetStatus(Me.DTO.Id, ba_id).ValidatedOwn Then
            Throw New PromoException("promo's content already validated")
        End If
        PROMO_DAL.Promo.LockUnlockOwn(Me.DTO.Id, ba_id, lock)
    End Sub
 
    Public Sub LockUnlockDemo(ba_id As Byte, lock As Boolean)
        If lock = False AndAlso PROMO_DAL.BuyingDepartment.GetStatus(Me.DTO.Id, ba_id).ValidatedDemo Then
            Throw New PromoException("promo's content already validated")
        End If
        PROMO_DAL.Promo.LockUnlockDemo(Me.DTO.Id, ba_id, lock)
    End Sub
 
    Public Sub Copy(description As String, startDate As Date, startTime As TimeSpan, endDate As Date, endTime As TimeSpan, type As PromoType)
        If Not PROMO_DAL.Promo.Copy(Me.DTO.Id, startDate, startTime, endDate, endTime, description, type.DTO.Id) Then
            Throw New Exception("promo overlaps")
        End If
    End Sub
 
    Public Class Conflict
        Public Property Own As PROMO_DTO.PromoDetailOwn
        Public Property Dept As PROMO_DTO.PromoDetailDepartment
        Public Sub New(own As PROMO_DTO.PromoDetailOwn, dept As PROMO_DTO.PromoDetailDepartment)
            Me.Own = own
            Me.Dept = dept
        End Sub
    End Class
 
    Private Sub CheckForDuplicateSeason(lng_id As Byte)
        If DTO.DetailsOwn IsNot Nothing Then
            Dim data = (From d1 As PROMO_DTO.PromoDetailOwn In DTO.DetailsOwn
                        From d2 As PROMO_DTO.PromoDetailOwn In DTO.DetailsOwn
                        Where d1.Brand.Id = d2.Brand.Id And d1.Department.Id = d2.Department.Id And d1.Id <> d2.Id And d1.Seasons.Intersect(d2.Seasons).Count > 0
                        Select New Conflict(d1, Nothing))
 
            For Each c As Conflict In data.ToList
                c.Own.ErrorText = If(lng_id = 1, "Seizoenen", "Saisons")
            Next
 
            If DTO.DetailsDepartment IsNot Nothing Then
                data = (From d1 As PROMO_DTO.PromoDetailOwn In DTO.DetailsOwn
                        Join d2 As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment On d1.Department.Id Equals d2.Department.Id
                        Where d1.Seasons.Intersect(d2.Seasons).Count > 0
                        Select New Conflict(d1, d2))
 
                For Each c As Conflict In data.ToList
                    c.Own.ErrorText = If(lng_id = 1, "Seizoenen", "Saisons")
                    c.Dept.ErrorText = If(lng_id = 1, "Seizoenen", "Saisons")
                Next
 
                data = (From d1 As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment
                         From d2 As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment
                         Where d1.Department.Id = d2.Department.Id And d1.Id <> d2.Id And d1.Seasons.Intersect(d2.Seasons).Count > 0
                         Select New Conflict(Nothing, d1))
 
                For Each c As Conflict In data.ToList
                    c.Dept.ErrorText = If(lng_id = 1, "Seizoenen", "Saisons")
                Next
            End If
        Else
            Dim data = (From d1 As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment
                        From d2 As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment
                        Where d1.Department.Id = d2.Department.Id And d1.Id <> d2.Id And d1.Seasons.Intersect(d2.Seasons).Count > 0
                        Select New Conflict(Nothing, d1))
 
            For Each c As Conflict In data.ToList
                c.Dept.ErrorText = If(lng_id = 1, "Seizoenen", "Saisons")
            Next
        End If
    End Sub
 
    Private Sub CheckForDoublePromo(lng_id As Byte)
        If DTO.DetailsOwn IsNot Nothing Then
            Dim data = (From d1 As PROMO_DTO.PromoDetailOwn In DTO.DetailsOwn
                        From d2 As PROMO_DTO.PromoDetailOwn In DTO.DetailsOwn
                        Where d1.Id <> d2.Id And d1.Brand.Id = d2.Brand.Id And d1.Department.Id = d2.Department.Id And d1.ListType = "" And d2.ListType = "" _
                        And ((d1.Seasons.Count >= 0 And d2.Seasons.Count = 0) Or (d1.Seasons.Count = 0 And d2.Seasons.Count >= 0))
                        Select New Conflict(d1, Nothing))
 
            For Each c As Conflict In data.ToList
                c.Own.ErrorText = If(lng_id = 1, "Dubbel promo", "Double promo")
            Next
 
            data = (From d1 As PROMO_DTO.PromoDetailOwn In DTO.DetailsOwn
                    From d2 As PROMO_DTO.PromoDetailOwn In DTO.DetailsOwn
                    Where d1.Id <> d2.Id And d1.Brand.Id = d2.Brand.Id And d1.Department.Id = d2.Department.Id _
                    And d1.PercentType.Description = "AUTO" And d2.PercentType.Description = "LIST" And (d2.ListType = "" Or d2.ListType = "EXC")
                    Select New Conflict(d2, Nothing))
 
            For Each c As Conflict In data.ToList
                c.Own.ErrorText = If(lng_id = 1, "Dubbel promo", "Double promo")
            Next
 
            If DTO.DetailsDepartment IsNot Nothing Then
                data = (From d1 As PROMO_DTO.PromoDetailOwn In DTO.DetailsOwn
                        Join d2 As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment On d1.Department.Id Equals d2.Department.Id
                        Where ((d1.Seasons.Count >= 0 And d2.Seasons.Count = 0) Or (d1.Seasons.Count = 0 And d2.Seasons.Count >= 0)) And d1.ListType = "" And d2.ListType = ""
                        Select New Conflict(d1, d2))
 
                For Each c As Conflict In data.ToList
                    c.Own.ErrorText = If(lng_id = 1, "Dubbel promo", "Double promo")
                    c.Dept.ErrorText = If(lng_id = 1, "Dubbel promo", "Double promo")
                Next
 
                data = (From d1 As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment
                        From d2 As PROMO_DTO.PromoDetailOwn In DTO.DetailsOwn
                        Where d1.Id <> d2.Id And d1.Department.Id = d2.Department.Id _
                        And d1.PercentType.Description = "AUTO" And d2.PercentType.Description = "LIST" And (d2.ListType = "" Or d2.ListType = "EXC")
                        Select New Conflict(d2, d1))
 
                For Each c As Conflict In data.ToList
                    c.Own.ErrorText = If(lng_id = 1, "Dubbel promo", "Double promo")
                    c.Dept.ErrorText = If(lng_id = 1, "Dubbel promo", "Double promo")
                Next
 
                data = (From d1 As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment
                        From d2 As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment
                        Where d1.Id <> d2.Id And d1.Department.Id = d2.Department.Id And d1.ListType = "" And d2.ListType = "" And ((d1.Seasons.Count >= 0 And d2.Seasons.Count = 0) Or (d1.Seasons.Count = 0 And d2.Seasons.Count >= 0))
                        Select New Conflict(Nothing, d1))
 
                For Each c As Conflict In data.ToList
                    c.Dept.ErrorText = If(lng_id = 1, "Dubbel promo", "Double promo")
                Next
            End If
        Else
            Dim data = (From d1 As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment
                        From d2 As PROMO_DTO.PromoDetailDepartment In DTO.DetailsDepartment
                        Where d1.Id <> d2.Id And d1.Department.Id = d2.Department.Id And d1.ListType = "" And d2.ListType = "" And ((d1.Seasons.Count >= 0 And d2.Seasons.Count = 0) Or (d1.Seasons.Count = 0 And d2.Seasons.Count >= 0))
                        Select New Conflict(Nothing, d1))
 
            For Each c As Conflict In data.ToList
                c.Dept.ErrorText = If(lng_id = 1, "Dubbel promo", "Double promo")
            Next
        End If
    End Sub
 
    Private Sub ResetErrorText()
        For Each d As PROMO_DTO.PromoDetailOwn In Me.DTO.DetailsOwn
            d.ErrorText = Nothing
        Next
        For Each d As PROMO_DTO.PromoDetailDepartment In Me.DTO.DetailsDepartment
            d.ErrorText = Nothing
        Next
    End Sub
 
    Public Sub CheckForConflicts(lng_id As Byte)
        If Me.DTO.DetailsOwn Is Nothing AndAlso Me.DTO.DetailsDepartment Is Nothing Then
            Exit Sub
        End If
        ResetErrorText()
        CheckForDuplicateSeason(lng_id)
        CheckForDoublePromo(lng_id)
    End Sub
End Class
 
Public Class Promos
    Public Property DTO As List(Of PROMO_DTO.Promo)
 
    Public Sub New()
        Me.DTO = New List(Of PROMO_DTO.Promo)
    End Sub
 
    Public Sub New(dto As List(Of PROMO_DTO.Promo))
        Me.DTO = dto
    End Sub
 
    Public Shared Function GetPromos(lng_id As Byte, inProgress As Boolean, toCome As Boolean, finished As Boolean, ba_id As Byte?) As Promos
        Return New Promos(PROMO_DAL.Promo.GetPromoList(lng_id, inProgress, toCome, finished, ba_id))
        'Dim dtos As List(Of PROMO_DTO.Promo) = PROMO_DAL.Promo.GetPromoList(lng_id, inProgress, toCome, finished, ba_id)
        'Dim result As Promos = New Promos
        'If Not dtos Is Nothing Then
        '    For Each dto As PROMO_DTO.Promo In dtos
        '        result.DTO.Add(dto)
        '    Next
        'End If
        'Return result
    End Function
 
    Public Function GetById(id As Integer) As PROMO_BLL.Promo
        Return New Promo((From d As PROMO_DTO.Promo In DTO
                         Where d.Id = id
                         Select d).FirstOrDefault)
    End Function
End Class


[EDIT 1]
En mettant un point d'arret dans l'event RowEnter du dgv, le debugger passe bien dans l'event et e.RowIndex vaut 0. Ce qui explique le changement de contenu.

Par contre, ça n'explique pas pourquoi il passe dans cet event...

Enfin j'imagine que ça doit être car l'utilisateur répond au MessageBox.Show, donc il disparaît, donc faut repeindre les contrôles, donc la grille est "réinitialisée"...

C'est quand même bizarre... Pourquoi dans cette application et pas dans les autres...


[EDIT 2]
J'ai trouvé la cause du problème...

J'ignore totalement pourquoi mais il y a du code dans l'event Form.Activated et ce code fait appel à la fonction qui charge les promos depuis la DB et recharge la grille. Du coup, le RowEnter de la grille s'enclenche et c'est la 1e promo qui est prise...

Quelqu'un aurait une idée de pourquoi j'aurais été utilisé cet event Form.Activated alors que ça ne sert en fait à rien ?