Hello,
I am looking for a quick solution - I came across really strange thing - I cannot bind the List<MyClass> to the WinGrid.MyClass has only properties of simple types: string, double etc.
In the designer mode, I clicked on DataSource of wingrid, and added new bindingsource - MyClass. Then I was able to modify column captions, hide some columns etc in designer mode.
I also added one unbound column which has got formula:
if(isblank([COL1]),0,[COL2]* [COL3]/ [COL1]) //says that compiled succesfully
But when I run my code:
List<MyClass> list = getlist(); //it has count=1 after that
wingrid.dataSource = list;
wingrid.databind();
I got the exception in the main thread, that "Object reference not set to an instance of an object."
I always binded ultragrid with datatable on the fly and everything was correct. Now, when i want to do that in a nicer way (bind to the list of business objects), it throws errors during the first binding in the runtime.
What can be a problem?
Can you post a stack trace of what you're experiencing? Since you're making the distinction that the exception is on the main thread, I'm guessing that you happen to be using multiple threads. Are you setting the DataSource on another thread? If so, you should definitely be invoking that logic back to the main UI thread.
-Matt
I made the distinction, because that was a strange exception - I could not catch it anywhere, I also tried to handle wingrid onerror, but it didn't go into that scope. I wrote really simple app- no multithreading. It just kicked out the error in :
static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); // <- here } }
Now I gave up fighting with that, I've just added one more property to myclass which makes the same computation as unbounded column in wingrid - it works now:) I hope that was something that grew up somewhere else in my code..
Thank you for the response:)