I have a problem with the ultrawingrid which I am using in my application.
a)Post the databind, the properties i set in the ultragrid designer for my bound columns, such as a 'hidden' property or 'no edit' property, they are lost on refreshing this grid (refresh being done by another database call which loads up the data).
- Is there a way i can retain this? I am currently working around this by doing this after the databind call.
Me
.grdName.DisplayLayout.GroupByBox.Hidden = True
.grdName.DisplayLayout.Bands(0).Columns(0).Format = "Someformat"
This appears to work fine. However, once in a while(say 1 time out of 10) I am getting an IndexOutOfRange Exception which, when i debug with my CLR exceptions to thrown, i am getting the columns(0), or columns(1) as nothing. Definitely not desirable. Is there a way I can manually work around this? Maybe put this in an event of some kind(like a databound event which i can see in the ultrawebgrid)?I am rather new to using infragistics controls and I'd greatly appreciate any help in this regard.Thanks a lot! Cheers!
HOWTO:How can I define columns in the grid at Design-time and bind them at run-time so that some fields of the data are excluded from the grid?
The IndexOutOfRange exception is probably an issue of timing. What event are you using for this code? The best event for code like this is the grid's InitializeLayout event.
Hmm I did not put it in the initialize layout code. Actually, i think the problem is related to the datagrid actually 'grabbing' data from the source across threads.I alleviated this by using a threadsafe method, and the invoke required property, the usage of which, was well explained in another infragistics thread. So far, i think its working just fine. On a related note,Is there any reason why , in the initializerow event of an ultragrid, only sometimes i find that when i try to access the cells using e.Row.Cells(0) or cells(1), i get another index out of range exception? I would assume the initialize row event would occur only after the row is added to the grid. I have put in some defensive code to prevent this exception, however, i still get it, albeit very rarely.
Private Sub grdName_InitializeRow(sender As Object, e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles grdName.InitializeRow
<<Defensive code if statement>>
<<Doing something on e.Row.Cells(2)>>
<<End defensive code check>>
Any pointers how to get around this? Maybe put this in another event like the initializegridlayout or something else? Thanks!
JohnSM said:Actually, i think the problem is related to the datagrid actually 'grabbing' data from the source across threads.
Ah, I see. That would certainly do it. You didn't mention anything in your original post about threading. I would strongly advise against using DataBinding and threading together. When using multiple threads, you have to make sure that any communication across those threads is properly marshalled from one thread to the other. And in a DataBinding scenario, you are not in control of the communication between the UI, the BindingManager, and the data source. So it's nearly impossible to do this safely.
JohnSM said:Is there any reason why , in the initializerow event of an ultragrid, only sometimes i find that when i try to access the cells using e.Row.Cells(0) or cells(1), i get another index out of range exception?
Yes, because the event is firing before the columns have been created. This can happen if you bind the grid more than once. For example, if you are trying to refer to the index of an unbound column that has not yet been added. Or if set the DataSource property of the grid and then set the DataMember.
You could avoid this by checking for the existence of the column you want before you try to reference it by the indexer. It's typically better to use the key in a case like this rather than the index, anyway, since the index can change.
But if you are checking the count first before you try to reference the column bu index and are still getting an error, then I'm sure it's another threading issue.