Bonjour,
J’ai travaillé pendant 10 ans en SSII sur des projets vba !
Je suis revenu depuis 2 ans dans une société pour laquelle je migre une application VB6 en vb.net.
Quand je parle de migration, il n’y a plus de références à Vb6 ! Et j’ai l’impression (c’est plus qu’une impression) de devoir tous réapprendre.
Je veux mutualiser certaines actions répétitives dans une classe qui intercepte les évènements d’un DataGridView. Je ne veux pas créer dynamiquement les contrôles mais gérer des contrôles existant dans un UsF.
Dites-moi où je pêche !
De plus j’ai implémenté la méthode Paste sur ce DataGridView et je trouve le traitement long ! Comment améliorer les performances.
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 Public Sub New(ByRef Dbgc As DataGridView) Dbg = Dbgc End Sub Public Property Dbg As DataGridView Get Return _Dbg End Get Set(value As DataGridView) _Dbg = value AddHandler _Dbg.CellMouseDown, AddressOf _Dbg_CellMouseDown End Set End Property Protected Sub _Dbg_CellMouseDown(sender As Object, e As Windows.Forms.DataGridViewCellMouseEventArgs) Handles _Dbg.CellMouseDown If e.Button = Windows.Forms.MouseButtons.Right Then PasteClipboardw() End If End Sub
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 Private Sub PasteClipboardw() Try Dim s As String = Clipboard.GetText() Dim lines As String() = s.Split(Environment.NewLine) Dim iFail As Integer = 0, iRow = _Dbg.CurrentCell.RowIndex Dim iCol As Integer = _Dbg.CurrentCell.ColumnIndex Dim oCell As DataGridViewCell Dim i As Integer = 0, c As Integer = 0 For i = 0 To lines.LongCount - 1 If iRow + i = _Dbg.RowCount Then _Dbg.DataSource.Rows.Add(_Dbg.DataSource.NewRow()) _Dbg.Refresh() End If Next i = 0 For Each line As String In lines Dim sCells As String() = line.Split(Convert.ToChar(Keys.Tab)) c = 0 For Each Col As String In sCells oCell = _Dbg(iCol + c, iRow + i) oCell.Value = FormaterChamp(Convert.ChangeType(Col.ToString, oCell.ValueType)) c += 1 Next i += 1 Next _Dbg.Refresh() Catch ex As Exception End Try End Sub
Partager