Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Cannot add items to dataviewgrid winforms

I've been searching for hours for an answer to my problem but I really can't find one. So basically I can add to dataviewgrid from any UI based function (label clicks, main, button clicks) but cannot add data if i create the function myself, I've tried every method I can find and they simply do not work. I even loaded up some of my older projects (i stopped using winforms) and I still couldn't figure it out.

My problem: Cannot add data to dataviewgrid from any function that isn't specifically winforms related

Please, someone put me out of my misery.
[Image: rXKOqlS.gif]

It's because you are not on the same Thread.

What you can do is invoke it using the invoke method of the datagridview.

So basically, to add you would use something like this:
Code
dataGridView1.Invoke((MethodInvoker)delegate {
   dataGridView1.Rows.Add(new string[] { "Content 1", "Content 1"});
   dataGridView1.Rows.Add(new string[] { "Content 1", "Content 1"});
});
(Jul 14, 2018 07:06 PM)TRH4CK Wrote:  It's because you are not on the same Thread.

What you can do is invoke it using the invoke method of the datagridview.

So basically, to add you would use something like this:
Code
dataGridView1.Invoke((MethodInvoker)delegate {
   dataGridView1.Rows.Add(new string[] { "Content 1", "Content 1"});
   dataGridView1.Rows.Add(new string[] { "Content 1", "Content 1"});
});

I also already tried this, I was given this error

Code
'Invoke or BeginInvoke cannot be called on a control until the window handle has been created.'

I'm aware of what it means but It's the very last block of code called, I'm not quite sure what else to do I've tired using IsHandleCreated and had no luck
[Image: rXKOqlS.gif]

Anyone got any ideas? I still haven't solved this.
[Image: rXKOqlS.gif]

I don't think we can help you much further without some source code that you are currently using and possibly an error message that you are getting :).
https://github.com/Washi1337

"I'll tell you this UDP joke, and I don't care if you will get it or not."
(Jul 21, 2018 04:26 AM)Washi Wrote:  I don't think we can help you much further without some source code that you are currently using and possibly an error message that you are getting :).

That's the thing, i've tried tons of ways of adding to the grid. At the moment I moved to using a datasource from my results. The error message is above but it's:
Code
Invoke or BeginInvoke cannot be called on a control until the window handle has been created.

But I don't understand why the handle isn't created, I've even tried to force create it.


Solved by modifying program.cs to include a work around for accessing form1.
[Image: rXKOqlS.gif]



Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by fisica638Feb 8, 2024 08:07 AM 8 557 Feb 8, 2024 08:07 AM
Last Post: fisica638
[C#] by SIM-587985Sep 23, 2022 08:23 AM 3 286 Sep 23, 2022 08:23 AM
Last Post: MavenGradle
[.NET] by SIM-3933056Apr 16, 2021 02:08 PM 29 1,217 Apr 16, 2021 02:08 PM
Last Post: centan