I’m working on a desktop application in C# (in Visual Studio 2010, framework 4.0). I have to display same (or slightly modified – without some columns) datagridview / table in different places. I’ll get the data from querying different (local) files. I find it very consuming to make a new query for each table. Thus I thought about binding tables with query. But I don’t know if it is the best way to do it. I don’t know how “expensive” it is to bind data to gridview. Maybe it would be better to somehow show the same table, maybe put it in a panel an then display it properly (moving it to different positions/user controls according to the user’s navigation).
These tables are not that big, but I’d need to display 4-5 of them in quite some locations and I don’t want to waste memory with them because there are also some very large tables.
Any ideas?
Thank you for your time and answers.
As Ken already stated you should put several
DataGridViewsinto your form. But you attach them all to the sameBindingSource. And to theBindingSource.DataSourceyou simply attach a list (collection, whatever) containing all the data after you grab it once.The setup and configuration of all data grids can be done at design time with the Visual Studio designer. To do this you should take a look into this answer. It explains how to create and a attach a binding source to a TextBox, but for a data grid is the same. After this binding in the designer you can afterwards dive into the Columns property of the grid with the designer and change the visibility, etc. of each column as you like.