0
votes

DevExpress Refreshing datagridview in vb.net not working.

I load one table from my database to datagridview and it display all the data

Problem - When I load another table from database to datagridview, It wasn't working. Only the first table will display its data while the second table won't display any data to datagridview.

2
And what doesn't work? I can assume that your second table has different columns (field names). So, you need to correct existing column field names - Gosha_Fighten
What happens? Empty rows or something else? - Marko Juvančič
Can you post your code so I can see exactly which objects/controls are in play? - Hambone
Yes @Gosha_Fighten. I have different columns (field names) in my next table. How can I change the column names base on my new table from database? - Vincent Bryan F. Calija
I got an empty rows @MarkoJuvančič. And the column names don't change. I still got the 1st table column headers. - Vincent Bryan F. Calija

2 Answers

0
votes

After you assign a new data source to the grid, call the GridView.PopulateColumns method to re-generate columns:

gridControl1.DataSource = secondDataTable;
GridView gv = (GridView)gridControl1.FocusedView;
gv.PopulateColumns(secondDataTable);
0
votes

There are two possible reasons for this kind of behavior:


  1. The columns are different in the second datatable.

The symptom of this is: you see as many empty row in the grid as there are rows in the second datatable.

Cause: Gridcontrol (gridview to be precise) already has Columns property and doesn't find matching pairs.

Solution: Call GridControl.PopulateColumns() after loading the second datatable. This will recreate Colums property.


  1. Gridview doesn't realize that the underlying datasource has been changed.

Symptom: you see old values.

Solution: Call GridView.Refresh()


As far as I can see from your comments, you have the former issue. So, do something in this manner:

gridControl.DataSource = myFirstDataTable();

/* some other code*/ 

gridControl.DataSource = mySecondDataTable();
(gridControl.MainView as ColumnView).PopulateColumns()