惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
SegmentFault 最新的问题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
F
Full Disclosure
Vercel News
Vercel News
N
News | PayPal Newsroom
The GitHub Blog
The GitHub Blog
H
Hacker News: Front Page
H
Heimdal Security Blog
P
Privacy International News Feed
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
L
Lohrmann on Cybersecurity
D
Docker
Recent Announcements
Recent Announcements
Security Archives - TechRepublic
Security Archives - TechRepublic
人人都是产品经理
人人都是产品经理
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
博客园 - 叶小钗
Google Online Security Blog
Google Online Security Blog
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
S
Secure Thoughts
博客园 - Franky
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
P
Palo Alto Networks Blog
Latest news
Latest news
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
Last Week in AI
Last Week in AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
Hacker News: Ask HN
Hacker News: Ask HN
T
Threatpost
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学

博客园 - lining

输出的客户端 - lining - 博客园 List<T> - lining - 博客园 DateTime 赋空值 配色达人速成 批处理文件,删除文件及文件夹 - lining - 博客园 Source Code中pfx的密码 查找所有有某一列的表 如何修改 app.config 的配置信息 用例的获得 如何oracle调试存储过程 C# 中String 和 string 有什么区别 ora-00997:非法使用LONG数据类型 oracle如何判断一个字符串是否为数字或日期 C# 中的计时器 winform技巧,listbox绑定,value,text, - lining - 博客园 查看oracle执行计划 “Windows Workflow Foundation开发实战系列课程”中的数据库恢复 ASP.NET多语言版的开发 oracle数据导入导出imp/exp命令
populate a listbox on winform with values from database
lining · 2010-06-18 · via 博客园 - lining

from->http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/9dcdf5a2-d3df-4d27-8352-1cfa9997b685

Hi,

how to populate a listbox on winform with values from database at runtime?  Can someone send code / links to articles on net for this..Once user selects clicks an item from this listbox, the selected item should be shown in a textbox. I have textbox in form 1 and listbox in form 2.

Thanks to help.

=================================================================

Hi, yasinirshad,

Based on my understanding, you want to know how to get the values from a DataBase and add them into a ListBox, don't you?

I wrote a small sample for you which can do this job.

Say, I am using a Acess DB and two forms.

In form1.

Code Block

DataTable table;

BindingSource source;

private void Form1_Load(object sender, EventArgs e)

{

OleDbConnection connection = new OleDbConnection(Properties.Settings.Default.newConnectionString);

OleDbDataAdapter adapter = new OleDbDataAdapter("select NAME, ID from Table1", connection);

table = new DataTable();

adapter.Fill(table); //Retrieve data from DataBase

source = new BindingSource();

source.DataSource = table;

this.textBox1.DataBindings.Add("Text", source, "Name"); //Bind the DataSource to the TextBox

Form2 form = new Form2(source);

form.Owner = this;

form.Show(this);

}

In form2

Code Block

public Form2(BindingSource source)

{

InitializeComponent();

listBox1.DisplayMember = "NAME";

listBox1.ValueMember = "ID";

listBox1.DataSource = source;

}

And the value in your TextBox will change with the selection in your ListBox.

More info

http://msdn2.microsoft.com/en-us/library/e80y5yhx(vs.80).aspx

http://msdn2.microsoft.com/en-us/library/ef2xyb33.aspx

Hope this helps,

Regards