根据选择填充gridview [英] Populate gridview according to selection

查看:105
本文介绍了根据选择填充gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我的列表框中有数据,如果我在列表框中选择一行,则将向网格视图加载一些信息.

现在,如果在列表框中选择了另一行,则将向gridview加载不同的信息.事情是我想覆盖gridview,每次选择一个选项时,然后在不删除先前信息的情况下加载网格

Hi guys

I have data in my listbox, if i select a row in listbox, a gridview is loaded with some information.

Now if another row is selected in a listbox, gridview is goin to be loaded with diffrent information. The thing is i want to overwrite the gridview, evry time i select an option,then the grid is loaded with out removing the previous information

how can i approach that??

推荐答案

使用List<yourobjecttype></yourobjecttype>存储数据并将其设置为datagridview的数据源

这样的东西
Use a List<yourobjecttype></yourobjecttype> to store the data and set this as the datasource of the datagridview

Something like this
// member vars
List<yourobjecttype> items = new List<yourobjecttype>();
DataGridView grid = new DataGridView();

// event handler for list item being changed
private void ListBoxIndexChanged(..)
{
   items.AppendRange(GetData());
   grid.DataSource = items;

}

private List<yourobjecttype> GetData()
{
    List<yourobjecttype> data = new List<yourobjecttype>();
    // retrieve data
    
    return data ;  
}</yourobjecttype></yourobjecttype></yourobjecttype></yourobjecttype></yourobjecttype>


这篇关于根据选择填充gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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