Bonjour à tous,

Je me suis développé une class héritant de datagridview avec le code suivant :

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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
 
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
using MarkNet.Models;
using MarkNet.Controlers;
using MarkNet.Gui;
 
namespace MarkNet.Gui.Controls
{
    public class DtgvMarks : DataGridView
    {
        //TODO: à fixer 
            //supptrimer scintillement/ralentissement léger lors du défillement avrec roulette
            // click pour menu qui ne charge pas le bon et necessité de double click
 
        #region Component model
 
        private System.Windows.Forms.ContextMenuStrip ctxAffichage;
        private System.ComponentModel.IContainer components;
        private System.Windows.Forms.ContextMenuStrip ctxDtgvMark;
        private System.Windows.Forms.ToolStripMenuItem ctxOpen;
        private System.Windows.Forms.ToolStripMenuItem ctxEffacer;
        private System.Windows.Forms.ToolStripMenuItem ctxVerrouiller;
        private System.Windows.Forms.ToolStripMenuItem ctxDeverrouiller;
        private System.Windows.Forms.ToolStripMenuItem ctxVerfier;
        private System.Windows.Forms.ToolStripMenuItem ctxUpdateUrl;
        private DataGridViewTextBoxColumn CheckColor;
        private DataGridViewTextBoxColumn CodeCheck;
        private DataGridViewTextBoxColumn Titre;
        private DataGridViewTextBoxColumn Link;
        private DataGridViewTextBoxColumn Fichier;
        private DataGridViewTextBoxColumn Redirection;
        private DataGridViewTextBoxColumn Description;
        private DataGridViewTextBoxColumn KeyWords;
        private DataGridViewTextBoxColumn ColorTraitement;
        private DataGridViewTextBoxColumn Traitement;
 
        private void InitializeComponent()
        {
			this.components = new System.ComponentModel.Container();
			this.ctxAffichage = new System.Windows.Forms.ContextMenuStrip(this.components);
			this.ctxDtgvMark = new System.Windows.Forms.ContextMenuStrip(this.components);
			this.ctxOpen = new System.Windows.Forms.ToolStripMenuItem();
			this.ctxEffacer = new System.Windows.Forms.ToolStripMenuItem();
			this.ctxVerrouiller = new System.Windows.Forms.ToolStripMenuItem();
			this.ctxDeverrouiller = new System.Windows.Forms.ToolStripMenuItem();
			this.ctxVerfier = new System.Windows.Forms.ToolStripMenuItem();
			this.ctxUpdateUrl = new System.Windows.Forms.ToolStripMenuItem();
			this.CheckColor = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.CodeCheck = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.Titre = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.Link = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.Fichier = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.Redirection = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.Description = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.KeyWords = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.ColorTraitement = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.Traitement = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.ctxDtgvMark.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
			this.SuspendLayout();
			// 
			// ctxAffichage
			// 
			this.ctxAffichage.Name = "ctxAffichage";
			this.ctxAffichage.Size = new System.Drawing.Size(61, 4);
			// 
			// ctxDtgvMark
			// 
			this.ctxDtgvMark.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.ctxOpen,
            this.ctxEffacer,
            this.ctxVerrouiller,
            this.ctxDeverrouiller,
            this.ctxVerfier,
            this.ctxUpdateUrl});
			this.ctxDtgvMark.Name = "contextMenuStrip1";
			this.ctxDtgvMark.Size = new System.Drawing.Size(157, 136);
			// 
			// ctxOpen
			// 
			this.ctxOpen.Name = "ctxOpen";
			this.ctxOpen.Size = new System.Drawing.Size(156, 22);
			this.ctxOpen.Text = "Ouvrir";
			// 
			// ctxEffacer
			// 
			this.ctxEffacer.Name = "ctxEffacer";
			this.ctxEffacer.Size = new System.Drawing.Size(156, 22);
			this.ctxEffacer.Text = "Effacer";
			// 
			// ctxVerrouiller
			// 
			this.ctxVerrouiller.Name = "ctxVerrouiller";
			this.ctxVerrouiller.Size = new System.Drawing.Size(156, 22);
			this.ctxVerrouiller.Text = "Verrouiller";
			// 
			// ctxDeverrouiller
			// 
			this.ctxDeverrouiller.Name = "ctxDeverrouiller";
			this.ctxDeverrouiller.Size = new System.Drawing.Size(156, 22);
			this.ctxDeverrouiller.Text = "Deverrouiller";
			// 
			// ctxVerfier
			// 
			this.ctxVerfier.Name = "ctxVerfier";
			this.ctxVerfier.Size = new System.Drawing.Size(156, 22);
			this.ctxVerfier.Text = "Verifier";
			// 
			// ctxUpdateUrl
			// 
			this.ctxUpdateUrl.Name = "ctxUpdateUrl";
			this.ctxUpdateUrl.Size = new System.Drawing.Size(156, 22);
			this.ctxUpdateUrl.Text = "Mise à jour URL";
			// 
			// CheckColor
			// 
			this.CheckColor.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
			this.CheckColor.HeaderText = "Couleur check";
			this.CheckColor.Name = "CheckColor";
			this.CheckColor.Resizable = System.Windows.Forms.DataGridViewTriState.False;
			this.CheckColor.ToolTipText = "Couleur check";
			this.CheckColor.Width = 20;
			// 
			// CodeCheck
			// 
			this.CodeCheck.HeaderText = "Code";
			this.CodeCheck.Name = "CodeCheck";
			this.CodeCheck.ToolTipText = "Code vérification";
			this.CodeCheck.Width = 75;
			// 
			// Titre
			// 
			this.Titre.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
			this.Titre.HeaderText = "Titre";
			this.Titre.Name = "Titre";
			this.Titre.ToolTipText = "Titre de la page";
			// 
			// Link
			// 
			this.Link.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
			this.Link.FillWeight = 75F;
			this.Link.HeaderText = "Lien";
			this.Link.Name = "Link";
			this.Link.ToolTipText = "Lien hypertext";
			// 
			// Fichier
			// 
			this.Fichier.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
			this.Fichier.HeaderText = "Fichier";
			this.Fichier.Name = "Fichier";
			this.Fichier.Resizable = System.Windows.Forms.DataGridViewTriState.False;
			this.Fichier.ToolTipText = "lien vers un fichier";
			this.Fichier.Width = 20;
			// 
			// Redirection
			// 
			this.Redirection.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
			this.Redirection.FillWeight = 75F;
			this.Redirection.HeaderText = "Redirection";
			this.Redirection.Name = "Redirection";
			this.Redirection.ToolTipText = "Lien de redirection";
			// 
			// Description
			// 
			this.Description.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
			this.Description.FillWeight = 50F;
			this.Description.HeaderText = "Description";
			this.Description.Name = "Description";
			this.Description.ToolTipText = "Description de la page";
			// 
			// KeyWords
			// 
			this.KeyWords.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
			this.KeyWords.FillWeight = 50F;
			this.KeyWords.HeaderText = "Mots clefs";
			this.KeyWords.Name = "KeyWords";
			this.KeyWords.ToolTipText = "Mots clefs";
			// 
			// ColorTraitement
			// 
			this.ColorTraitement.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
			this.ColorTraitement.HeaderText = "Couleur traitement";
			this.ColorTraitement.Name = "ColorTraitement";
			this.ColorTraitement.Resizable = System.Windows.Forms.DataGridViewTriState.False;
			this.ColorTraitement.ToolTipText = "Couleur de traitement";
			this.ColorTraitement.Width = 20;
			// 
			// Traitement
			// 
			this.Traitement.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
			this.Traitement.FillWeight = 25F;
			this.Traitement.HeaderText = "Traitement";
			this.Traitement.Name = "Traitement";
			this.Traitement.ToolTipText = "Traitement en cours";
			// 
			// DtgvMarks
			// 
			this.AllowUserToAddRows = false;
			this.AllowUserToDeleteRows = false;
			this.AllowUserToResizeRows = false;
			this.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.CheckColor,
            this.CodeCheck,
            this.Titre,
            this.Link,
            this.Fichier,
            this.Redirection,
            this.Description,
            this.KeyWords,
            this.ColorTraitement,
            this.Traitement});
			this.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically;
			this.EnableHeadersVisualStyles = false;
			this.RowHeadersVisible = false;
			this.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
			this.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DtgvMarksNew_CellDoubleClick);
			this.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.DtgvMarksNew_CellFormatting);
			this.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DtgvMarks_ColumnHeaderMouseClick);
			this.SelectionChanged += new System.EventHandler(this.DtgvMarksNew_SelectionChanged);
			this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.DtgvMarksNew_KeyUp);
			this.MouseEnter += new System.EventHandler(this.DtgvMarksNew_MouseEnter);
			this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.DtgvMarksNew_MouseUp);
			this.ctxDtgvMark.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this)).EndInit();
			this.ResumeLayout(false);
        }
 
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
 
        #endregion
 
 
        public new event EventHandler SelectionChanged;
        private void OnSelectionChanged()
        { if (SelectionChanged != null) SelectionChanged(this, EventArgs.Empty); }
 
 
        public event EventHandler CheckMark;
        private void OnCheckMark()
        { if(CheckMark != null) CheckMark(this, EventArgs.Empty); }
 
        public event EventHandler OpenMark; //With use events
        private void OnOpenMark()
        { if (OpenMark != null) { OpenMark(this, EventArgs.Empty); } }
 
        public event EventHandler DeleteMark; //With use events
        private void OnDeleteMarks()
        { if (DeleteMark != null) { DeleteMark(this, EventArgs.Empty); } }
 
        public event EventHandler LockMark; //With use events
        private void OnLockMark()
        { if (LockMark != null) { LockMark(this, EventArgs.Empty); } }
 
        public event EventHandler UnLockMark; //With use events
        private void OnUnLockMark()
        { if (UnLockMark != null) { UnLockMark(this, EventArgs.Empty); } }
 
 
        public const int COLCCHECKCOLOR = 0;
        public const int COLCODECHECK = 1;
        public const int COLTITRE = 2;
        public const int COLLINK = 3;
        public const int COLISFILE = 4;
        public const int COLREDIRECTION = 5;
        public const int COLDESCRIPTION = 6;
        public const int COLKEYWORDS = 7;
        public const int COLCOLORTRAITEMENT = 8;
        public const int COLTRAITEMENT = 9;
 
        private MarksCtrlr _markCtrl = new MarksCtrlr();
		private OrderCtrlr _orderCtrlr = new OrderCtrlr();
		private bool _useEvents = false;
        private bool _suspendEvent = false;
        private Dictionary<string, bool> _colsShow = new Dictionary<string, bool>();
        private List<Mark> _lst = new List<Mark>();
        protected bool _inProgress = false;
 
 
        public List<Mark> SelectedMarks
        {
            get
            {
                List<Mark> lst = new List<Mark>();
                foreach (DataGridViewRow row in SelectedRows)
                {
                    lst.Add(Rows[row.Index].DataBoundItem as Mark);
                }
                return lst;
            }
        }
 
 
        public bool UseEvents
        {
            get { return _useEvents; }
            set { _useEvents = value; }
        }
 
        public Dictionary<string, bool> ColShow
        {
            set
            {
            	if(value != null)
            		_colsShow = value;
            	else
            		throw new ArgumentNullException();
 
                SuspendLayout();
                for (int i = 1; i < Columns.Count; i++)
                {
                    if (_colsShow.ContainsKey(Columns[i].Name))
                        Columns[i].Visible = _colsShow[Columns[i].Name];
                    else
                        Columns[i].Visible = false;
                }
                createContextMenuAffichage();
                ResumeLayout();
            }
        }
 
 
 
        public DtgvMarks()
        {
            InitializeComponent();
            AutoGenerateColumns = false;
 
            SetCLickMenu();
            createContextMenuAffichage();
 
		}
 
 
 
        public void SetMarks(List<Mark> lst)
        {
            if (lst.Count == 0 || lst == null) return;
 
            DataSource = null;
            Rows.Clear();
 
            Columns[COLTITRE].DataPropertyName = "Titre";
            Columns[COLLINK].DataPropertyName = "Link";
            Columns[COLDESCRIPTION].DataPropertyName = "Description";
            Columns[COLKEYWORDS].DataPropertyName = "KeyWords";
			Columns[COLCODECHECK].DataPropertyName = "CodeCheck";
			Columns[COLREDIRECTION].DataPropertyName = "Redirection";
 
			_lst = lst;
 
			_lst = _orderCtrlr.OrderMarks(_lst);
 
            DataSource = _lst;
 
			ClearSelection();
		}
 
 
 
		#region "event on datagridview"
 
		private void DtgvMarks_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
		{
			//TODO: a définir sur base de l'ordonnacement grandissant ou non  + mise à jour header... A placer sur simple click
			//TODO: vérifier si click sur colonne déjà selectionnée et changer juste le mode de l'ordre. (dans control order??)
 
			if (e.Button == MouseButtons.Right) return;
 
			SuspendLayout();
 
			for (int i = 0; i < ColumnCount; i++)
			{
				Columns[i].HeaderCell.Style.BackColor = Color.LightGray;
				Columns[i].HeaderCell.SortGlyphDirection = SortOrder.None;
			}
 
			DataSource = _orderCtrlr.OrderMarks(_lst, Columns[e.ColumnIndex].DataPropertyName);
			EnableHeadersVisualStyles = false;
			Columns[e.ColumnIndex].HeaderCell.Style.BackColor = Color.LightBlue;
			if(_orderCtrlr.AscendingOrder == true)
				Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = SortOrder.Ascending;
			else
				Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = SortOrder.Descending;
			ResumeLayout();
		}
 
		private void DtgvMarksNew_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (Rows.Count == 0) return;
 
            int colIndex = e.ColumnIndex;
            int rowIndex = e.RowIndex;
 
            Mark mk = Rows[rowIndex].DataBoundItem as Mark;
 
            switch (colIndex)
            {
                case COLCCHECKCOLOR:
                    Rows[rowIndex].Cells[COLCCHECKCOLOR].Style.BackColor = mk.CheckInfo.Couleur;
                    break;
                case COLLINK:
                    if (Helpers.UrlHlp.IsFromDarkWeb(mk.Link)) Rows[rowIndex].Cells[COLLINK].Style.ForeColor = Color.Red;
                    break;
                case COLISFILE:
                    if (Helpers.FileHlp.UrlIsFile(mk.Link) == true)
                    {
                        Rows[rowIndex].Cells[COLISFILE].Value = " ";
                        Rows[rowIndex].Cells[COLISFILE].Style.BackColor = Color.Black;
                    }
                    break;
            }
        }
 
        private void DtgvMarksNew_SelectionChanged(object sender, EventArgs e)
        {
            if (_suspendEvent == false)
                OnSelectionChanged();
        }
 
        private void DtgvMarksNew_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1) return;
            MarkOpen();
        }
 
        private void DtgvMarksNew_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete) DeleteMarks();
            if (e.KeyCode == Keys.Enter) MarkOpen();
        }
 
        private void DtgvMarksNew_MouseEnter(object sender, EventArgs e)
        {
            Focus();
        }
 
        #endregion
 
        #region Context menu
 
        private void DtgvMarksNew_MouseUp(object sender, MouseEventArgs e)
        {
			if (e.Button == MouseButtons.Left) return;
 
				this.ContextMenuStrip = null;
 
				DataGridView dgv = (DataGridView)sender;
				var hit = dgv.HitTest(e.X, e.Y);
				ContextMenuStrip cms = null;
				switch (hit.Type)
				{
					case DataGridViewHitTestType.ColumnHeader:
						cms = ctxAffichage;
						break;
					case DataGridViewHitTestType.Cell:
						cms = ctxDtgvMark;
						break;
				}
				if (cms != null)
					cms.Show(this, e.Location);
        }
 
        public void createContextMenuAffichage()
        {
            ctxAffichage.Items.Clear();
 
            List<ToolStripItem> lst = new List<ToolStripItem>();
            ToolStripMenuItem tsm;
 
            for (int i = 0; i < Columns.Count; i++)
            {
                tsm = new ToolStripMenuItem();
                tsm.Name = Columns[i].Name;
                tsm.Text = Columns[i].HeaderText;
                tsm.Checked = Columns[i].Visible;
                tsm.Click += Tsm_Click;
                tsm.Tag = Columns[i].Name;
                lst.Add(tsm);
            }
 
            ctxAffichage.Items.AddRange(lst.ToArray());
        }
 
        private void SetCLickMenu() //pas dans le initialize car supprime l'ensemble des evenment click lors de modification en graphique
        {
            ctxOpen.Click += CtxOpen_Click;
            ctxEffacer.Click += CtxEffacer_Click;
            ctxVerrouiller.Click += CtxVerrouiller_Click;
            ctxDeverrouiller.Click += CtxDeverrouiller_Click;
            ctxVerfier.Click += CtxVerfier_Click;
            ctxUpdateUrl.Click += CtxUpdateUrl_Click;
        }
 
        private void Tsm_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem tsm = sender as ToolStripMenuItem;
 
            if (tsm.Checked == true)
                tsm.Checked = false;
            else
                tsm.Checked = true;
 
            for (int i = 0; i < Columns.Count; i++)
            {
                if (Columns[i].Name == tsm.Name)
                    Columns[i].Visible = tsm.Checked;
            }
        }
 
        private void CtxOpen_Click(object sender, EventArgs e)
        {
            MarkOpen();
        }
 
        private void CtxEffacer_Click(object sender, EventArgs e)
        {
            DeleteMarks();
        }
 
        private void CtxVerrouiller_Click(object sender, EventArgs e)
        {
            LockMarks();
        }
 
        private void CtxDeverrouiller_Click(object sender, EventArgs e)
        {
            UnLockMarks();
        }
 
        private void CtxVerfier_Click(object sender, EventArgs e)
        {
            OnCheckMark();
        }
 
        private void CtxUpdateUrl_Click(object sender, EventArgs e)
        {
            UrlUpdate();
        }
 
		#endregion
 
		#region Actions
 
		private void MarkOpen()
        {
            if (_useEvents == true)
                OnOpenMark();
            else
                MarksCtrlr.OpenMark(Rows[CurrentCell.RowIndex].DataBoundItem as Mark);
        }
 
        private void DeleteMarks()
        {
            if (SelectedRows.Count == 0) return;
 
            if (_useEvents == true)
                OnDeleteMarks();
            else
                RemoveSelectedMarks();
        }
 
        private void LockMarks()
        {
            if (_useEvents == true)
            {
                OnLockMark();
            }
            else
            {
                //FIXME: raffraichissement du datagridview ne fonctionne pas.
                _markCtrl.LockMarks(SelectedMarks);
                this.Refresh();
            }
            /*else
			{
				//TODO: a simplifier
					/*int itemselected = .SelectedIndex;
					int topIndex = lstDomaines.TopIndex;
					List<Domaine> lst = SelectedDomaines;
 
					_domCtrlr.LockDomaines(lst);
 
					lstDomaines.SelectedItems.Clear();
					lstDomaines.TopIndex = topIndex;
					lstDomaines.SelectedIndex = itemselected;	
			}*/
        }
 
        private void UnLockMarks()
        {
            if (_useEvents == true)
            {
                OnUnLockMark();
            }
 
 
            //TODO: a simplifier
            /*	int itemselected = this.lstDomaines.SelectedIndex;
                int topIndex = lstDomaines.TopIndex;
                List<Domaine> lst = SelectedDomaines;
 
                _domCtrlr.UnLockDomaines(lst);
 
                lstDomaines.SelectedItems.Clear();
                lstDomaines.TopIndex = topIndex;
                lstDomaines.SelectedIndex = itemselected;			
        }	*/
        }
 
        private void UrlUpdate() //TODO: A completer
        {
            List<Mark> lst = SelectedMarks;
            int nbVerrouille = lst.Count(x => x.Locked == true);
 
            if (nbVerrouille != 0)
                /*_markCtrl.*/
                return;
            else
                return;
 
            Refresh();
        }
 
        public void AutomatiqueSortable()
        {
            foreach (DataGridViewColumn column in Columns)
            {
                column.SortMode = DataGridViewColumnSortMode.Automatic;
            }
        }
 
        public void AutomatiqueNotSortable()
        {
            foreach (DataGridViewColumn column in Columns)
            {
                column.SortMode = DataGridViewColumnSortMode.NotSortable;
            }
        }
        #endregion
 
        public void ChangeRowColor(int rowindex, Color color, string message = "")
        {
            Rows[rowindex].Cells[COLCOLORTRAITEMENT].Style.BackColor = color;
            Rows[rowindex].Cells[COLTRAITEMENT].Value = message;
        }
 
        public void RemoveSelectedMarks()
        {
            List<Mark> lst = SelectedMarks;
            int nbVerrouille = lst.Count(x => x.Locked == true);
			int topIndex = FirstDisplayedScrollingRowIndex;
 
 
			if (nbVerrouille != 0)
                _markCtrl.RemoveMarks(lst, DialogBox.DeleteLockedMark(nbVerrouille));
            else
                _markCtrl.RemoveMarks(lst, true);
 
            SuspendLayout();
 
            _lst = _lst.Except(lst).ToList();
			//TODO: réordonner la list comme avant....
            DataSource = _lst;
 
			if(lst.Count != 0 ) //TODO: vérifier si pas null....
				FirstDisplayedScrollingRowIndex = topIndex;
 
			ResumeLayout();
        }
 
 
	}
}
Le problème vient que lorsque j'ajoute ce control sur une form/usercontrol, le mode design ajoute automatiquement des colonnes au même nombre que celle existante dans ma class dtgvMarks. Il faut à chaque fois que j'aille supprimer en manuel les lignées ajoutée par le designer pour ne pas les avoir en double.

Comment faire pour que le designer n'ajoute pas les lignes en doubles?