LISTVIEW每行的随机ID(LISTVIEW random id for each row)

   IT问题网   2021-02-24 00:00:00

问 题

嗨,



我想要的是每行可以为我的列表视图生成一个id吗?

例如我有listview中的10条记录,我想随机添加每行id ...







请帮忙..





提前感谢

解决方案

有一些方法可以生成一个唯一的id:



1- 使用random()函数生成随机数,您可以将其用作id。

2- 使用system.guid.newguid()生成guid并使用它。这将是一个字母数字值。

3- 如果你将它作为identity列并返回该值以用作id,你也可以使用数据库表生成

4- 编写自己的自定义逻辑...



您的案例的解决方案应该是这样的:



私有randomclass为新随机



对于i = 0到cint(10) -1

stridamp; = mid( strcodes,int(len(strcodes)* randomclass.next())+ 1,1)

下一页



对于i = 0 to cint(4) -1

strid2amp; = mid(strcodes,int(len(strcodes)* randomclass.next())+ 1,1)

next





而不是使用randomize()rnd(),我在这里使用random类及其方法next()来生成一个每次都有新的随机数。您还可以在调用next()方法时将随机数的最小值和最大值作为参数提供。





希望这会给你带来一些想法做出决定你想做什么。

prdshukla,感谢您的意见,但我已经构建了一个逻辑结构......但我的问题是我的子项目中的每一行第3列每个都有相同的id,我想要的是每行的随机id。我是vb.net的新手,我不知道如何处理这类问题...





这里''我的示例代码





lt; pre lang ="vb"gt; 

public const a as string ="abcdefghijklmnopqrstuvwxyz"
public const b as string ="0123456789"

lstlicense.items.clear()
lstlicense .enabled = true

dim strcodes as string
dim strid as string
dim strid2 as string
dim zz as string
dim item as listviewitem
dim random as new random
strcodes = strcodesamp; a
strcodes = strcodesamp; b

随机化()

对于i = 0到cint(10) -1
stridamp; = mid(strcodes,int(len(strcodes)* rnd())+ 1,1)
下一个

对于i = 0到cint(4) -1
strid2amp; = mid(strcodes,int(len(str) )* rnd())+ 1,1)
下一个

zz = stridamp; " - "amp; strid2


txtpartnumber.text = zz


对于d as integer = 0 to datagridview1.rows.count-2


使用商品

item = lstlicense.items.add(datagridview1.item(1,d).value.tostring,0)
item.subitems.add(datagridview1 .item(3,d)。value.tostring)2
item.subitems.add(zz)

结束
下一步

感谢您的回复..



但是我收到了一个错误





''算术运算导致溢出。''

私有randomclass为新随机

对于i = 0到cint(10) -1
stridamp; = mid(strcodes,int(len(strcodes)* randomclass.next())+ 1,1)
下一个

对于i = 0到cint(4) -1
strid2amp; = mid(strcodes,int(len(strcodes)* randomclass.next())+ 1,1)
next

标签:每行随机



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

如何创建自定义Web控件......?(How to create a custome web control...)

problem 1) i want to create a class that will inherited f ...

如何管理该代码(how to manage that code)

problem my question is......... we have 3 buttns on page ...

如何删除sysobjects中的列数据但不删除它们的关系(how to delete columns data in sysobjects but not deleted their relations)

problem hello how to delete all system table columns dat ...

异步wcf调用和mantaining会话?(asynchronous wcf call and mantaining session )

problem i have two pages on my website .from page 1 i am ...

通过网络传递序列化数据(Passing serialized data over network)

problem hey, i have a problem with deserializing an objec ...

程序显示按完成时间排序的跑步者,其中一列显示其年龄组内的完成位置(排名)。(Program to display the runners sorted by finish time with a column showing their finish position (ranking) within their age group.)

problem you have a list of runners and their race times a ...

如何调试我的xpath并检查它是否存在一些问题?(How to debug my xpath and to check if there are some problems in it )

problem hi,everyone! now i have a xml file and it looked ...

用户界面设计(User interface Design)

problem hi, i want to design all the user interface scree ...

在ASP.Net中拖放图像(Drag and drop image in ASP.Net)

problem hi, i saw "the drag and drop image i ...

任何人都可以帮助解决'/'应用程序中的服务器错误。(Can any one help dis error Server Error in '/' Application.)

problem hi every one i am upload one .aspx p ...

灰度图像处理(Gray Scale image Processing)

problem hi i want cut the image from pattern the output o ...

如何从javascript调用jsp页面(How to invoke jsp page from javascript)

problem how to invoke jsp page from javascript solution h ...

如何为字符串附加字符。(How can I append characters for a string .)

problem hello all, i have to append lt;stxgt ...

C#Yahoo Messenger注册表观察者(C# Yahoo Messenger registry watcher)

problem hi, my name is nicusor, i have found this code on ...

想要开始编码DMP打印机(Want to start Coding For DMP Printers)

problem hii.......... friends i want to sta ...

如何获取放置在gridview行中的服务器控件的客户端ID(How to get Client id of server control placed in gridview row)

problem hi i am creating row in gridview dynamicaly, hav ...

制作“制作文件”时出错UNIX(Error while making "Make File" unix)

problem i have 7 files which are as follows:; -hw1.cpp -m ...

邀请Facebook好友加入asp.net(Invite Facebook friends in asp.net)

problem hello all, how can i invite facebook friends usin ...

从另一个文件夹获取数据相同的解(get data from another folder same solution)

problem hello, i have a solution which consist of a folde ...

datagridview头过滤器(datagridview header filter)

problem i''ve been trying to make my datagridview filter ...