Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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??
Posted

1 solution

Use a List<yourobjecttype></yourobjecttype> to store the data and set this as the datasource of the datagridview

Something like this
C#
// 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>
 
Share this answer
 
v2
Comments
Anele Ngqandu 7-Nov-11 9:07am    
Why cant i find "AppendRange"?? the intellisense
Reiss 8-Nov-11 1:57am    
Sorry it is AddRange for a List

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900