如何将ListBox2中的值(具有重复值)移动到ListBox4中(非重复值)? [英] How to move value in ListBox2(with Duplicate value) to ListBox4 (Non Duplicate value)?

查看:71
本文介绍了如何将ListBox2中的值(具有重复值)移动到ListBox4中(非重复值)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将ListBox2中的值(具有重复值)移动到ListBox4中(非重复值)?条件,每个值都必须> =或< =3.
例如:
每个列表框都有5个值.
ListBox2:
6
8
8
12
15

ListBox4:
6
9- 8变成9,因为8-6 = 2(必须== 3)
20- 8变成20,因为我们随机取值
12
15

这是我的代码:

How to move value in ListBox2(with Duplicate value) to ListBox4 (Non Duplicate value)? The condition, each value must >= or <= 3 from other.
For example:
Each ListBox have 5 values.
ListBox2:
6
8
8
12
15

ListBox4:
6
9 --&gt; 8 become 9, because 8-6=2 (Must &gt;= 3)
20 --&gt; 8 become 20, because we random the value
12
15

Here''s my code :

Private Sub MaxGenome_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MaxGenome.TextChanged
        Dim i, nilai As Integer
        ListBox2.Items.Clear()
        ListBox4.Items.Clear()
        For i = 1 To CInt(PjgGen.Text)
            nilai = GeneticAlgorithm.PopuMain.Best_member.Genome(i)
            If Not (ListBox4.Items.Contains(nilai - 1) OrElse ListBox4.Items.Contains(nilai - 2) OrElse ListBox4.Items.Contains(nilai) OrElse ListBox3.Items.Contains(nilai + 1) OrElse ListBox4.Items.Contains(nilai + 2)) Then
                ListBox4.Items.Add(nilai)
            Else
                While (ListBox4.Items.Contains(nilai - 1) OrElse ListBox4.Items.Contains(nilai - 2) OrElse ListBox4.Items.Contains(nilai) OrElse ListBox3.Items.Contains(nilai + 1) OrElse ListBox4.Items.Contains(nilai + 2))
                    Do
                        nilai = Rand_between(1, CInt(record.Text))
                    Loop
                    If Not (ListBox4.Items.Contains(nilai - 1) OrElse ListBox4.Items.Contains(nilai - 2) OrElse ListBox4.Items.Contains(nilai) OrElse ListBox3.Items.Contains(nilai + 1) OrElse ListBox4.Items.Contains(nilai + 2)) Then
                        ListBox4.Items.Add(nilai)
                    End If
                End While
            End If
            ListBox2.Items.Add(GeneticAlgorithm.PopuMain.Best_member.Genome(i))
        Next i
    End Sub



此操作从TextBox2.TextChanged开始.每TextBox2.TextChanged,将调用此操作.我清除了ListBox项目中下一个值的空间.

对不起,我的英语不好,仅关注示例,这是我问题的重点,谢谢微笑:)



This operation begin when TextBox2.TextChanged. Every TextBox2.TextChanged, this operation will be called. I''m clear the ListBox Item for space to the next value.

Sorry my english is bad, just focus on the example, that''s the main point of my question, thanks Smile :)

推荐答案

我不知道VB. NET好.但是您可以使用 Linq [相交 [例外 [ ^ ]

借助此to方法,您可以轻松找到常见的事物.
I do not know VB.NET well. But you can give it a shot with Linq[^]. There is a nice method Intersect[^] and Except[^]

With this to method you can find things that are in common in a easy way.


这篇关于如何将ListBox2中的值(具有重复值)移动到ListBox4中(非重复值)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆