使用计时器输入新记录时重新加载listiview项目 [英] reloading listiview items when new record is entered using timer

查看:96
本文介绍了使用计时器输入新记录时重新加载listiview项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿..检查数据库是否有新的输入记录是否可行?如果检测到一个..列表视图将被重新设置?我试图创建这种功能,但它对我不起作用,我有以下代码



private sub list_load()''这是用于重新加载listview项目

dim strsql as string

dim rsload as new adodb.recordset

dim x as integer

dim list as listviewitem



strsql =select * from customer''这只是一个示例查询



with rsload

.open(strsql,conn)

do .eof = false

list = lstcustomer.items.add(.fields(0 )。值)

for x = 1到3步1

list.subitems(x).text = .fields(x).value

next x

.movenext

loop

.close

结束

end sub



''这将是计时器的代码--------------------- -

dim strsql as string

dim rsload as n ew adodb.recordset



dim count as integer

dim counthandler as integer



x:



strsql =select count(*)as total from customer



with rsload

.open(strsql,conn)

如果.eof = false那么

count = .fields(total)。value

如果counthandler =什么,那么

counthandler = count + 1

else

''什么都不做

结束如果

endif

.close

结束



如果coumthandler = count那么

调用list_load''调用list_load子

else

''没有什么

endif



转到x

----------------------- -----------------------

问题是代码不能工作..我的项目只是挂起。并且代码的目的是我尝试局域网连接。当lan项目输入新记录时,主项目应检测到已添加新记录,如果检测到新记录,则应再次自动重新加载listview项目。



如果我只是使用计时器每1,2,3秒重新加载listview项目会很容易,但我认为创建一个代码来检查是否有新记录输入会很好..



请帮忙,提前谢谢.. :)

解决方案

您好,好友



雅,当你在表格中添加任何记录或数据然后自动提醒我们时你是对的。

但这是不可能的bcoz数据库只能安全地存储数据,并在我们的查询中提供我们的信息。



如果你想在表格中添加新记录,

为此你需要通过查询重新加载你的表格。



你的项目第二件事就是挂起bcoz你没有完美地管理你的表格和功能格式。



从表中为getdata创建一个函数

公共函数GetData()



该函数调用时你需要桌子的数据



重新加载你的数据创建一个你已创建的计时器,但给出一些暂停的时间。

Ex。每隔五分钟或一分钟拿着计时器





 公开  Form1 

' 在表单加载时配置计时器
私有 Sub Form1_Load( ByVal sender As System。 Object ,< span class =code-keyword> ByVal e As System.EventArgs)句柄 < span class =code-keyword> MyBase .Load
' 打开计时器
Timer1.Enabled = True
' 设置每个计时器的间隔tic k
Timer1.Interval = 3000 ' 那个时间以毫秒计算
结束 Sub

' 对每个计时器执行的操作:
私有 Sub Timer1_Tick( ByVal sender 作为系统。对象 ByVal e As System.EventArgs)句柄 Timer1.Tick
MessageBox.Show( 此消息框将每3秒弹出一次! www.interloper.nl,MessageBoxButtons.OK,MessageBoxIcon.Information)
结束 Sub

结束





如果有任何疑惑,请回答我的回答。



请使用不同功能或类别的除法编码来改善您的编码。

为此不要在系统上加载。



Happy Coding好友:)

 


hey.. is it posible to check if database have new inputed records? and if detected one.. the listview would be reloted? i have tried to create that kind of function but it doesnt work for me, i have the codes below

private sub list_load() ''this is for reloading listview items
dim strsql as string
dim rsload as new adodb.recordset
dim x as integer
dim list as listviewitem

strsql = "select * from customer" ''this is just a sample query

with rsload
.open (strsql,conn)
do while .eof = false
list = lstcustomer.items.add(.fields(0).value)
for x = 1 to 3 step 1
list.subitems(x).text = .fields(x).value
next x
.movenext
loop
.close
end with
end sub

''this will be the code for the timer-----------------------
dim strsql as string
dim rsload as new adodb.recordset

dim count as integer
dim counthandler as integer

x:

strsql = "select count(*) as total from customer"

with rsload
.open (strsql,conn)
if .eof = false then
count = .fields("total").value
if counthandler = nothing then
counthandler = count + 1
else
''do nothing
end if
endif
.close
end with

if coumthandler = count then
call list_load ''calls the list_load sub
else
''no nothing
endif

goto x
----------------------------------------------
the problem is that the code wont work.. my project just hangs. and the purpose of the code is that im trying a lan connection. whenever lan project enters new record, the main project should detect that new record has been added, and if it detects one the listview items should be automatically reloaded again.

it would be easy if i just reload listview items every 1,2,3 seconds using a timer, but i think creating a code for checking if new record has been entered would be good..

please help, advance thanks..:)

解决方案

Hello, Buddy

Ya, you are right for when any record or data add in table then automatically alert to we.
But that is not possible bcoz Database work only that store data safely and give our information in requirement in our query.

If you want to detect new record when add in table,
For that you need to reload your table contains through query.

second thing your project was going to hang bcoz you not manage your Forms and Functions in perfect format.

Create one function for getdata from your table
Public funtion GetData()

That function call when you need data of table

For reload your data Create one timer that already you created, But give some timing for hold.
Ex. every five minute or one minite holding timeter


Public Class Form1

    'Configure the timer at form load
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Turn on the timer
        Timer1.Enabled = True
        'Set the interval for each timer "tick"
        Timer1.Interval = 3000      'That time give in miliseconds
    End Sub

    'Actions to perform on each timer tick:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        MessageBox.Show("This messagebox will popup every 3 seconds!", "www.interloper.nl", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

End Class



If any confusing, comment on my answer.

Please improve your coding with divide coding in different function or classes.
For that don''t loading on system.

Happy Coding buddy :)


这篇关于使用计时器输入新记录时重新加载listiview项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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