(NET) NET (2019)

3.4. My typical VB.NET desktop application. Navigate in DataGrid and TreeView.


To navigate Up-Down in GridView need to do this simple code:


 115:      Private Sub GridViewDownButton_Click(sender As Object, e As EventArgs) Handles GridViewDownButton.Click
 116:          If EmailCenterSubformDataGridView.SelectedRows IsNot Nothing Then
 117:              If EmailCenterSubformDataGridView.SelectedRows.Count > 0 Then
 118:                  Dim CurIndex As Integer = EmailCenterSubformDataGridView.SelectedRows(0).Index
 119:                  If CurIndex < EmailCenterSubformDataGridView.Rows.Count - 1 Then
 120:                      EmailCenterSubformDataGridView.ClearSelection()
 121:                      EmailCenterSubformDataGridView.Rows(CurIndex + 1).Selected = True
 122:                  End If
 123:              End If
 124:          End If
 125:      End Sub

Also need to handle directly click on row:


 142:      Private Sub EmailCenterSubformDataGridView_SelectionChanged(sender As Object, e As EventArgs) Handles EmailCenterSubformDataGridView.SelectionChanged
 143:          If EmailCenterSubformDataGridView.SelectedRows IsNot Nothing Then
 144:              If EmailCenterSubformDataGridView.SelectedRows.Count > 0 Then
 ...   
 184:              End If
 185:          End If
 186:      End Sub

The similar operation in TreeView - UpDown navigation and handle in node click is look as:


 291:      Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect
 292:          Dim Nodes As String() = e.Node.FullPath.Split("\")
 293:          IDUser1.SelectText(Nodes(0))
 294:          If Nodes.Count > 1 Then IDMailBox.SelectText(Nodes(1))
 295:      End Sub
 296:   
 297:      Dim SelectedNode As TreeNode
 298:      Private Sub TreeViewDownButton_Click(sender As Object, e As EventArgs) Handles TreeViewDownButton.Click
 299:          If TreeView1.SelectedNode Is Nothing Then
 300:              SelectedNode = TreeView1.TopNode
 301:              TreeView1.SelectedNode = TreeView1.TopNode
 302:              TreeView1.SelectedNode.Expand()
 303:          End If
 304:          TreeView1.SelectedNode = TreeView1.SelectedNode.NextVisibleNode
 305:      End Sub
 306:   
 307:   
 308:      Private Sub TreeViewUpButton_Click(sender As Object, e As EventArgs) Handles TreeViewUpButton.Click
 309:          If TreeView1.SelectedNode Is Nothing Then
 310:              SelectedNode = TreeView1.TopNode
 311:              TreeView1.SelectedNode = TreeView1.TopNode
 312:              TreeView1.SelectedNode.Expand()
 313:          End If
 314:          TreeView1.SelectedNode = TreeView1.SelectedNode.PrevVisibleNode
 315:      End Sub
 316:  #End Region

And ListView has similar evens too:


 199:      Dim MailAttachments As IEnumerable(Of MimeKit.MimeEntity)
 200:      Private Sub AttachmentListListView_Click(sender As Object, e As EventArgs) Handles AttachmentListListView.Click
 201:          If AttachmentListListView.SelectedItems.Count > 0 Then
 202:              Dim SelectedAtt As String = AttachmentListListView.SelectedItems(0).Text
 ...   
 218:          End If
 219:      End Sub


< THANKS ME>