将数据添加到DatagridView WinForms [英] Adding data to DatagridView WinForms

查看:103
本文介绍了将数据添加到DatagridView WinForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的C#Windows表单中添加了一个datagridview.我有4列,行数为19.在同一Windows窗体上,我还有一个列表框.如果选择了列表框中的一个项目(SelectedIndexChanged),则该项目的所有信息(4个类别)(存储在数据库表中)应显示在datagridview的4个不同列中.当选择在列表框下一个项目,这些信息应该在DataGridView的4列再次dsplayed,但下一个可用行?

datagridview未链接到任何数据源.

I have added a datagridview to my C# Windows form. I have 4 columns, and a row count of 19. On the same Windows Form, I also have a list box. If an item in the listbox is selected (SelectedIndexChanged), all the info of that item (4 catagories), which is stored in a database table, should be displayed in the 4 different columns of the datagridview. When next item in listbox is selected, that information should be dsplayed in the 4 columns of the datagridview again, but in next available row?

The datagridview is not linked to any datasource.

推荐答案

在列表框的选定索引更改中,
从数据库中获取所需的数据,并将其存储到DataTable对象中.
并将其作为数据源分配给列表框,
下次获取数据时,只需将其添加到DataTable对象.

为了避免这么多数据库命中,您可以一次拥有所有数据,并根据列表框中的选定值使用DatView对其进行过滤.

例如,执行Google/Bing搜索.
In selected index change of the listbox,
get the required data from the database, store it into a DataTable object.
and assign it as a datasource to the listbox,
next time you get the data, just add it to the DataTable object.

For avoiding so many database hits, you may have all the data at once and filter it using a DatView according to the selected value in the list box.

For examples, do a Google/Bing search.


http ://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid = 240221 [

这篇关于将数据添加到DatagridView WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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