What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Using gps.LoadDataBase in an SelectedIndexChanged event

Status
Not open for further replies.

tictoc

Member
Joined
Sep 21, 2012
Messages
380
Reaction score
5
Hi,

i do have a forms gui with a combobox to select one of a few Gps Database files in my plugin folder.

Now i want to load a new selected file when i do get the SelectedIndexChanged event, but when i try i do get an exception error:
Object reference not set to an instance of an object

I can change gui elements within this event, but i cannot use AB methods.
Looking now for hints how to fix that ...

Greetings,
tictoc
 
Null reference exception its hard to trace without read the code. What is in your event? How do you get the db3 path?

I already did a similar code and its work:
Code:
        private Gps _gps = new Gps(core); // core is your plugin class

        private void SelectedIndexChanged(object sender, EventArgs e)
        {
            var file = ((ComboBox)sender).SelectedValue; 
            // assuming your ComboBox is filled with full path of file, if not, you need to convert to full path
            // also you can use Path.Combine(core.pluginPath, "/YourPluginFolder/" + filename);
            _gps.LoadDataBase(file);
        }
 
As my SelectedIndexChanged is already similar i have concentrated on what can go wrong with:
Code:
        private Gps _gps = new Gps(core); // core is your plugin class

I had some more initialization code for the form class
Code:
        public MyPluginForm()
        {
            InitializeComponent();

            ... my additional code ...
        }

which was executed during Form initialization before core was set for this class.
After moving this additional code in the method which sets the core first, everything works fine.

Thanks,
tictoc
 
You can also inject core in form using the constructor:

Code:
private Core _core;

public MyPluginForm(Core core)
{
      InitializeComponent();
      _core = core;
}
 
Status
Not open for further replies.
Back
Top