منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
سؤال عن المقارنة في ListBox - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم اسئلة VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=183)
+--- الموضوع : سؤال عن المقارنة في ListBox (/showthread.php?tid=3356)

الصفحات: 1 2


سؤال عن المقارنة في ListBox - aftfm - 29-06-14

السلام عليكم ورحمة الله وبركاته

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

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


RE: سؤال عن المقارنة في ListBox - aftfm - 29-06-14

وهناك ملاحظة اخرى

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

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

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


RE: سؤال عن المقارنة في ListBox - Motaz Alnuweiri - 29-06-14

وعليكم السلام ورحمة الله 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

مرفق تصحيح الكود


RE: سؤال عن المقارنة في ListBox - aftfm - 29-06-14

اشكرك اخي العزيز

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

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

بعد ارساله الى ListBox2


RE: سؤال عن المقارنة في ListBox - aftfm - 30-06-14

لم اجد لسؤالي جواب


RE: سؤال عن المقارنة في ListBox - salfig - 30-06-14

وعليكم السلام
يمكنك عمل هذا في الدات ListView اما ListBox لا اعرف


RE: سؤال عن المقارنة في ListBox - Motaz Alnuweiri - 30-06-14

تفضل أخي 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



RE: سؤال عن المقارنة في ListBox - aftfm - 30-06-14

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


RE: سؤال عن المقارنة في ListBox - Motaz Alnuweiri - 30-06-14

الملف الذي ذكرته لايوجد فيه أي سطر متكرر أخي !!


RE: سؤال عن المقارنة في ListBox - aftfm - 30-06-14

جرب المثال مع الملف

التكرار يكون من بعد الاحرف