JonBrehaut
asked on
DatagridView in Custom User Control in VB.NET not loading data
I'm trying to build a custom user component which utilises a datagridview within it.
The problem is, no matter what I try, I cannot get the grid to load a datasource, it just ignores it.
It seems to be down to the fact the grid is in a Component class as calling out the supplied data to a grid on the form works everytime.
Has anyone come across this before and/or knows how to cure it?
(Attached is source example and screenshots of problem area). To test enter 'sm' in surname field, a grid should pop-up with matching records.
DatagridViewLoad.jpg
DatagridViewControl.jpg
AutocompleteDataGridViewIssue.zip
The problem is, no matter what I try, I cannot get the grid to load a datasource, it just ignores it.
It seems to be down to the fact the grid is in a Component class as calling out the supplied data to a grid on the form works everytime.
Has anyone come across this before and/or knows how to cure it?
(Attached is source example and screenshots of problem area). To test enter 'sm' in surname field, a grid should pop-up with matching records.
DatagridViewLoad.jpg
DatagridViewControl.jpg
AutocompleteDataGridViewIssue.zip
IMHO it's visible/invisible issue. AFAIK DataGridView calculates layout only when need (including .ColumnsCount, .RowsCount etc), so when dgv (or its container) is invisible .ColumnsCount = 0
ASKER
Erik: The Bindsource is set, it may be unclear from the code but it has a data table, like I mentioned the 'external' grid on the form receives the bindingsource perfectly happily on from the Event call "ShowData".
Ark: Good idea however doesn't seem to work in practice: I've rearranged the code and have made the grid (and container) visible before setting the source and it still does the same thing.
Ark: Good idea however doesn't seem to work in practice: I've rearranged the code and have made the grid (and container) visible before setting the source and it still does the same thing.
So why when I tried your code, the grid remained empty? With my modification, it was filled.
ASKER
Eric: The problem is not with the datagrid in the form (which is just there for testing purposes): The issue is with the datagrid being created on the fly, I did try your code and that grid still remains blank (dark grey) or did it work for you (in which case it must point to some other issue?)
have you tested my fix with the sample you attached to this question or with something else?
ASKER
With the sample supplied
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's it, now works perfectly. Brilliant find, many thanks I'd almost given up on it.
Friend WriteOnly Property LookupData() As DataTable
Set(value As DataTable)
p_LookupData = value
p_BindingSource.DataSource
RaiseEvent ShowData(p_BindingSource)
End Set
End Property