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

推荐订阅源

T
Threatpost
S
Securelist
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tenable Blog
I
Intezer
G
GRAHAM CLULEY
Spread Privacy
Spread Privacy
T
Tor Project blog
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Schneier on Security
Schneier on Security
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
S
Security @ Cisco Blogs
The Register - Security
The Register - Security
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
L
LangChain Blog
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
The Hacker News
The Hacker News
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
U
Unit 42
博客园 - 叶小钗
Attack and Defense Labs
Attack and Defense Labs
Webroot Blog
Webroot Blog
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
aimingoo的专栏
aimingoo的专栏
T
Troy Hunt's Blog
V
Visual Studio Blog
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
Arctic Wolf
T
The Exploit Database - CXSecurity.com
宝玉的分享
宝玉的分享
Vercel News
Vercel News
D
DataBreaches.Net
P
Palo Alto Networks Blog
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - 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