Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey!

So I have various variables set, that are then sent to form 'MethodLight' with this code:

MethodLight MethodLight = new MethodLight();
            MethodLight.AddGridViewRows(Quantity, Interleave, FixtureID, ChannelID, Manufacture, Fixture, Mode, Channels, Weight, Watts, Amps, PowerInput, PowerOutput, Lamp, DataConnection, FixturePos


And in form 'MethodLight' I had this code:

public void AddGridViewRows(int Quantity, int Interleave, int FixtureID, int ChannelID, string Manufacture, string Fixture, string Mode, string Channels, string Weight, string Watts, string Amps, string PowerInput, string PowerOutput, string Lamp, string DataConnection, string Position)
        {
            AddFixtures AddFixtures = new AddFixtures();
            FixtureDataView.Rows.Add(FixtureID, ChannelID, Manufacture, Fixture, Mode, Channels, Weight, Watts, Amps, PowerInput, PowerOutput, Lamp, DataConnection, Position);
        }


But when I click on the button that sends the data to
AddGridViewRows
, nothing happens at all, no data is added to the datagridview.

Any ideas?

Cheers

What I have tried:

I have tried different ways to add the data, like through an array, but nothing seems to work
Posted
Updated 16-Mar-19 9:45am
Comments
[no name] 16-Mar-19 15:23pm    
You made some stuff up. You should do some tutorials.

1 solution

Simple: it's a new instance of the form, the code is very specific about that. Which means that the data is added to the DGV in the new instance not any existing instance. And since your code doesn't call Show or ShowDialog on the new instance, nobody gets to see the new data.

You need to add it to the existing instance that the user is looking at ...
 
Share this answer
 
Comments
Member 14153081 16-Mar-19 18:19pm    
How would I go about using the same form without creating a new instance then? When I do MethodLight.AddGridViewRows I get an error saying that it needs a reference object?

Ideas?
OriginalGriff 17-Mar-19 2:45am    
You need to start by looking at what you do with the form when you first create the instance - look for a line which uses "new MethodLight()" and see where you store the reference. That's the value you are looking for, but unless you store it at class level, you won't be able to get at it easily again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900