将项添加到listview1中,如果该项已经在listview1中或已替换,则删除该项(Adding item into listview1 and remove if the item has already in the listview1 or replace)
我有
listview1
有2列。 我已经有了添加项目的代码但我的问题是当我再次添加listview1
的相同项目时,它显示重复项,当我继续添加相同的项目时,listview中的项目正在增加相同的数据。我需要的例子:
当
listview1
已经在第1列= 1和第2列= A中的数据时,我想再次添加像第1列= 1和第2列= B这样的数据。我有2个解决方案,我尝试编码但没有运气。 我的2个解决方案是:
- 我只想更新第二列中的数据,从“A”到“B”但是具有相同的第一列数据,并且没有其他项目将被添加到列表视图中,就像更新/替换它一样。
要么
- 删除将导致重复的项目并添加相同的项目,这样就不会有重复项。
这是我添加项目的代码:
Private Sub rbChoiceA_Checked(ByVal sender As Object, ByVal e As EventArgs) Dim rbA As RadioButton = TryCast(sender, RadioButton) Dim str As String = rbA.Parent.Name str = str.Remove(0, 6) lab1.Text = str Dim item As ListViewItem Dim row As String() = New String(2) {} row(0) = str row(1) = rbA.Text item = New ListViewItem(row) ListView1.Items.Add(item) End Sub
我只是需要帮助来添加我的问题的代码。 非常感谢您的回答。 提前致谢!
I have
listview1
with 2 columns. I already have a code for adding items but my problem is when I add again the same item inlistview1
, it shows duplicates and when I continue to add the same item, the items in listview are increasing with same data.Example for what I need:
When
listview1
has already a data in 1st column = 1 and in 2nd column = A, and I want to add again with a data like these 1st column = 1 and in 2nd column = B. I have 2 solutions and I try to code it but with no luck. My 2 solutions is these:
- I just want to update only the data in 2nd column, from "A" to "B" but with the same 1st column data and no additional item will be added into listview like nothing just update/replace it.
OR
- Remove the item that will cause duplication and add the same item so there will be no duplicates.
Here's my code for adding item:
Private Sub rbChoiceA_Checked(ByVal sender As Object, ByVal e As EventArgs) Dim rbA As RadioButton = TryCast(sender, RadioButton) Dim str As String = rbA.Parent.Name str = str.Remove(0, 6) lab1.Text = str Dim item As ListViewItem Dim row As String() = New String(2) {} row(0) = str row(1) = rbA.Text item = New ListViewItem(row) ListView1.Items.Add(item) End Sub
I just need help to add the code for my problem. Your answers is highly appreciated. Thanks in advance!
原文:https://stackoverflow.com/questions/40832127
最满意答案
尝试以下操作:
who | awk '{w[$1]++} END { for (x in w) { print x,"has "w[x]"active sessions" }}'
Try the following:
who | awk '{w[$1]++} END { for (x in w) { print x,"has "w[x]"active sessions" }}'
相关问答
更多-
如果你想要count用户登录的次数,那么通过command-line IMO就不可能....特别是因为有sudo选项假装其他用户可能会失败你的逻辑 - 如果你有任何 此外,有how many times需要有一个时间段( from when when )..所以你需要一个上限时间段,你要从中追踪计数。所有这将是一个混乱理想只是为了保持count 如果我必须跟踪它,我最好的猜测是拥有一个script并维护一个db-table保持登录users的count ! If you want count of how ...
-
尝试以下操作: who | awk '{w[$1]++} END { for (x in w) { print x,"has "w[x]"active sessions" }}' Try the following: who | awk '{w[$1]++} END { for (x in w) { print x,"has "w[x]"active sessions" }}'
-
uniq的问题是它只会折叠相邻的重复行。 在你的情况下-d在uniq上隐藏了分解重复行的行,我猜你有一些类似于reboot 4.4.5-1-ARCH Wed Mar当天登录尝试之间的行。 您也会遇到多个用户登录分解其他用户的计数的问题。 通常你sort | uniq sort | uniq获取uniq行的真实列表但是如果你删除了-d,你最终会得到你不想要的行。 这些最好在sort | uniq之前或之后单独过滤掉 sort | uniq 。 最后sort -u将删除数据,如果两行恰好匹配,我不认为这是你想要 ...
-
您正在使用$user ,但需要$USER 。 喜欢, count=$(who | grep $USER | wc -l) echo "$USER is logged on $count times." 我明白了 efrisch is logged on 4 times. 另一种选择是printf类的 printf "%s is logged on %s times.\n" $USER $(who | grep $USER | wc -l) 为了相同的结果。 You are using $user, b ...
-
PHP Count登录用户(PHP Count Logged-In Users)[2023-03-12]
您应该添加LastTimeSeen列,而不是IsLoggedIn列。 任何时候一个人访问一个页面,你都会更新该列: UPDATE members SET LastTimeSeen = NOW() WHERE id = $the_user_id 然后,在任何特定时刻使用查询来获取网站上有多少人: SELECT COUNT(*) FROM members WHERE LastTimeSeen > DATE_SUB(NOW(), INTERVAL 5 MINUTE) 这表明有多少人在过去的5分钟内浏览了一个页 ... -
您可以更通用,并处理任意数量的未知颜色/水果对,如下所示: awk '{if(NF==2){fruit[$2][$1]++}} END{for(color in fruit){for(type in fruit[color]){print color " " type " " fruit[color][type]}}}' 这将给出以下输出: yellow lemons 1 yellow apples 2 yellow grapes 3 green lemons 2 green apples 3 green ...
-
awk '{ for (i=1;i<=NF;i++) if ( $i == "2010" ) count++ } END { print count }' myfile.txt awk '{ for (i=1;i<=NF;i++) if ( $i == "2010" ) count++ } END { print count }' myfile.txt
-
在awk中,数组可以通过字符串或数字进行索引,因此您可以像关联数组一样使用它。 但是,你所要求的awk很难用得可靠,因为分隔符是空格,因此空字段会抛出列,如果你使用FIELDWIDTHS你也会被长于指定宽度的列抛出。 如果您要查找的只是每天的登录次数,您可能需要使用sed和awk(以及排序)的组合: last | \ sed -E 's/^.*(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( ...
-
需要帮助AWK脚本(Need help AWK script)[2024-02-16]
如果查询的结构保持不变,您可以使用: awk -F'[).]' '{print $3".%"}' 我使用右括号或文字点作为分隔符。 这样做的兴趣值在第3栏。 虽然它很简单,但会在用户面前留下一些空白。 我们可以增强字段分隔符regex来解决这个问题: awk -F')[[:space:]]*|[.]' '{print $3".%"}' 顺便说一句,你可以使用这个sed命令: sed 's/.*)[[:space:]]*\([^.]*\).*/\1.%/' 或者如果你有GNU grep,请使用: gre ... -
我不记得你可以在awk中使用反引号。 productCount=`system( systemCall )`-1; #subtract 1 to remove column label row 您可以通过不使用系统直接运行命令来读取输出,而是使用getline: systemCall | getline productCount productCount -= 1 或者更完整 productFile = "BusinessObjects.csv" systemCall = "cut ...