I am trying the below code by not able to execute it properly, because as soon as first if is cleared then the other if statement take the previous i value. that is when i = 2 is accepted then i remain 2 all time.
below is the code i am using
please help me
For i = 0 To lvHistory.Items.Count - 1
If lvHistory.Items(i).SubItems(0).Text <> 0 Then
If lastdt = "01-01-1900" Then
lastdt = lvHistory.Items(i).SubItems(2).Text
End If
If lvHistory.Items(i).SubItems(2).Text = lastdt Then
If lvHistory.Items(i).SubItems(6).Text = "2Diagnosis" Then
'Copy all details of Htype(6) = Diagnosis
'Inserting values inside Listview
Dim j As Integer
Dim lst1 As New ListViewItem(j)
lst1.SubItems.Add(cmbPatient.SelectedValue) 'PatientId 1
lst1.SubItems.Add(dtVisit.Text) 'Visit Date 2
lst1.SubItems.Add(lvHistory.Items(i).SubItems(3).Text) 'History Of 3
lst1.SubItems.Add(lvHistory.Items(i).SubItems(4).Text) 'HistoryId
lst1.SubItems.Add(lvHistory.Items(i).SubItems(5).Text) 'History Details
lst1.SubItems.Add(lvHistory.Items(i).SubItems(6).Text) 'History type
lst1.SubItems.Add(lvHistory.Items(i).SubItems(7).Text) 'DurationId
lst1.SubItems.Add(lvHistory.Items(i).SubItems(8).Text) 'Remarks
lst1.SubItems.Add(lvHistory.Items(i).SubItems(9).Text) 'Duration
lst1.SubItems.Add(lvHistory.Items(i).SubItems(10).Text) 'DBRemarks
lvHistory.Items.Add(lst1)
Dim flag As Boolean = True
For Each l As ListViewItem In lvHistory.Items
Dim strmyGroupname As String = l.SubItems(2).Text
For Each lvg As ListViewGroup In lvHistory.Groups
If lvg.Name = strmyGroupname Then
l.Group = lvg
flag = False
End If
Next
If flag = True Then
Dim lstGrp As New ListViewGroup(strmyGroupname, strmyGroupname)
lvHistory.Groups.Add(lstGrp)
l.Group = lstGrp
End If
flag = True
Next
' Figure out the new sorting order.
Dim sort_order As System.Windows.Forms.SortOrder = SortOrder.Descending
' Create a comparer.
lvHistory.ListViewItemSorter = New ListViewComparer(2, sort_order)
' Sort.
lvHistory.Sort()
End If
End If
End If
Next