هذا مثال للماقرنة في listBox1 عن الاسطر المكرر
وهو يقوم بارسال المكرر الى ListBox2
اريد تحديد السطر المكرر المكرر في ListBox1
وذلك بتلوينه أو تحديده بأي طريقة
Private Sub Deleted()
Dim ItemsToDelete As New List(Of Integer)
For I As Integer = 0 To ListBox1.Items.Count - 1
For J As Integer = I + 1 To ListBox1.Items.Count - 1
If Not ItemsToDelete.Contains(J) Then
If LCase(ListBox1.Items(I)) = LCase(ListBox1.Items(J)) Then
ItemsToDelete.Add(J)
End If
End If
Next
Next
Dim Count As Integer = 0
For Each I As Integer In ItemsToDelete
ListBox2.Items.Add(ListBox1.Items(I - Count))
ListBox1.Items.RemoveAt(I - Count)
Count += 1
lblFileName2.Text = "Deleted: " & Count
Next
End Sub
For I As Integer = 0 To ListBox1.Items.Count - 1
For J As Integer = I + 1 To ListBox1.Items.Count - 1
If Not ItemsToDelete.Contains(J) Then
If LCase(ListBox1.Items(I)) = LCase(ListBox1.Items(J)) Then
ItemsToDelete.Add(J)
End If
End If
Next
Next
Dim Count As Integer = 0
For Each I As Integer In ItemsToDelete
ListBox2.Items.Add(ListBox1.Items(I - Count))
'ListBox1.Items.RemoveAt(I - Count)
Count += 1
lblFileName2.Text = "Deleted: " & Count
Next
ListBox1.Invalidate()
End Sub
Private Sub ListBox1_DrawItem(sender As System.Object, e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
Dim MyBrush As SolidBrush = SystemBrushes.WindowText
If ItemsToDelete.Contains(e.Index) Then
MyBrush = New SolidBrush(Color.Red)
End If
Dim MyListBox As ListBox = CType(sender, ListBox)
If MyListBox.Items.Count > 0 Then
e.DrawBackground()
e.Graphics.DrawString(MyListBox.Items(e.Index), e.Font, MyBrush, e.Bounds)
e.DrawFocusRectangle()
End If
End Sub
لكن لم يعمل معي الكود هل جربته اقصد
هل قمت بقراءة الملف المرفق في سؤالي وبعد استرخاج المكرر نفذت الكود الذ قمت بوضع لي
إقتباس :Dim ItemsToDelete As New List(Of Integer)
Private Sub Deleted()
ItemsToDelete.Clear()
For I As Integer = 0 To ListBox1.Items.Count - 1
For J As Integer = I + 1 To ListBox1.Items.Count - 1
If Not ItemsToDelete.Contains(J) Then
If LCase(ListBox1.Items(I)) = LCase(ListBox1.Items(J)) Then
ItemsToDelete.Add(J)
End If
End If
Next
Next
Dim Count As Integer = 0
For Each I As Integer In ItemsToDelete
ListBox2.Items.Add(ListBox1.Items(I - Count))
'ListBox1.Items.RemoveAt(I - Count)
Count += 1
lblFileName2.Text = "Deleted: " & Count
Next
ListBox1.Invalidate()
End Sub
Private Sub ListBox1_DrawItem(sender As System.Object, e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
Dim MyBrush As SolidBrush = SystemBrushes.WindowText
If ItemsToDelete.Contains(e.Index) Then
MyBrush = New SolidBrush(Color.Red)
End If
Dim MyListBox As ListBox = CType(sender, ListBox)
If MyListBox.Items.Count > 0 Then
e.DrawBackground()
e.Graphics.DrawString(MyListBox.Items(e.Index), e.Font, MyBrush, e.Bounds)
e.DrawFocusRectangle()
End If
End Sub
المعذرة ارجوا تحميل مثالي السابق وفيه مجلد باسم File فيه ملف نصي اقراءة بالبرنامج ونفذ المقارنه يعمد بشكل جيد
المطلوب بعد التنفيذ تحديد السطر الذي تكرر
او تلوينه