从windows应用程序中读取列表框中的所有项目c# [英] Read all item from listbox in windows application c#
本文介绍了从windows应用程序中读取列表框中的所有项目c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Windows窗体c#中有两个列表框,第一个列表框目前有所有有效房间,第二个列出了当前房间给客人,用户可以通过此列表框之间的转移来更改此数据。
例如:
list1:1d,5d,6d,1r,12r
list2:2d,4d
用户可以删除2d而不是6d。
我需要什么如何在用户更新之后读取list2中的所有数据,并使用它来更新我在sql server中的表。
感谢您的帮助
I have two listbox in windows Form c#, the first one has all valid rooms at this time & the 2nd has the current rooms reserved to the Guest, & the user can change this data by transfer between this listboxex.
as example:
list1: 1d ,5d ,6d , 1r, 12r
list2: 2d, 4d
the user can delete 2d and put instead of it 6d.
what I need how can I read all data from list2 after user update it, & use this to update my table in sql server.
Thanks for help
推荐答案
listbox2.Items
是ListBox
中所有项目的集合。我会遍历集合并使用每个项目更新数据库。
listbox2.Items
is a collection of all of the items in theListBox
. I would cycle through the collection and update the database with each item.
foreach (string item in listBox2.Items)
{
// same the item to the database
}
string TimeslotItems = "";
foreach (ListItem item in listBox2.Items)
{
TimeslotItems += item.ToString() + ","; // /n to print each item on new line or you omit /n to print text on same line
}
这篇关于从windows应用程序中读取列表框中的所有项目c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文