منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : سؤال عن المقارنة في ListBox
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
الصفحات : 1 2
السلام عليكم ورحمة الله وبركاته

وكل عام وانتم بخير

هذا مثال للماقرنة في listBox1 عن الاسطر المكرر
وهو يقوم بارسال المكرر الى ListBox2
اريد تحديد السطر المكرر المكرر في ListBox1
وذلك بتلوينه أو تحديده بأي طريقة
وهناك ملاحظة اخرى

في المثال وبالتحديد في كود المقارنة في السطر

كود :
ListBox1.Items.Remove(DuplicateItem)

لحذف المكرر من ListBox1 لا يعمل
مع أنه في حالة الوصول لحل تلوينه يكفي وسيستغنى عن حذفة
وعليكم السلام ورحمة الله Smile

وأنت بخير أخي Wink

تفضل أخي .. إن شاء الله هذا يكون طلبك

كود :
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

مرفق تصحيح الكود
اشكرك اخي العزيز

لكن لم يحدث اي تغيير عند الاستخدام

المطلوب هو تلوين السطر المكرر في listbox1

بعد ارساله الى ListBox2
لم اجد لسؤالي جواب
وعليكم السلام
يمكنك عمل هذا في الدات ListView اما ListBox لا اعرف
تفضل أخي Smile

كود :
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
الف شكر اخي العزيز Motaz Alnuweiri

Shy

لكن لم يعمل معي الكود هل جربته اقصد
هل قمت بقراءة الملف المرفق في سؤالي وبعد استرخاج المكرر نفذت الكود الذ قمت بوضع لي
إقتباس :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 فيه ملف نصي اقراءة بالبرنامج ونفذ المقارنه يعمد بشكل جيد
المطلوب بعد التنفيذ تحديد السطر الذي تكرر
او تلوينه
الملف الذي ذكرته لايوجد فيه أي سطر متكرر أخي !!
جرب المثال مع الملف

التكرار يكون من بعد الاحرف
الصفحات : 1 2