Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Newbie: Problem invoking??

Newbie: Problem invoking??

Scheduled Pinned Locked Moved C#
helpdatabasedebuggingquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Phillip Hodges
    wrote on last edited by
    #1

    Hello all, I have run into a problem... I am trying to call a method from a thread but it is throwing an exception... System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object." Source="System.Windows.Forms" Here is the code: public void zap_publish_listview(zap item) { if (listView_main.InvokeRequired) { SetZapPublishListview s = new SetZapPublishListview(zap_publish_listview); Invoke(s, new object[] { item }); } else { // Extract data from zap item int icon = getStatusIconNumber(item.zap_state.ToString()); string name = item.zap_channel.ToString(); string data = item.zap_state.ToString(); // Create listview item ListViewItem lvItem = new ListViewItem("", icon); lvItem.SubItems.Add("ZAP: " + name); lvItem.SubItems.Add(data); lvItem.ToolTipText = item.ToString(); lvItem.Group = listView_main.Groups[2]; // ZAP group is index 2 // Find location of listview item to be replaced ListViewItem old_item = listView_main.FindItemWithText("ZAP: " + name, true, 0); // If item exists if (old_item.Index >= 0) { // Insert listview item listView_main.Items.Insert(old_item.Index, lvItem); // Remove old item listView_main.Items.RemoveAt(old_item.Index); } else { // Insert listview item listView_main.Items.AddRange(new ListViewItem[] { lvItem }); } } } I have a similar method that updates a debug window... And that works fine... Can anyone help??? Thanks in advance, Phil

    "Rules are for the obedience of fools and the guidance of wise men"

    C 1 Reply Last reply
    0
    • P Phillip Hodges

      Hello all, I have run into a problem... I am trying to call a method from a thread but it is throwing an exception... System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object." Source="System.Windows.Forms" Here is the code: public void zap_publish_listview(zap item) { if (listView_main.InvokeRequired) { SetZapPublishListview s = new SetZapPublishListview(zap_publish_listview); Invoke(s, new object[] { item }); } else { // Extract data from zap item int icon = getStatusIconNumber(item.zap_state.ToString()); string name = item.zap_channel.ToString(); string data = item.zap_state.ToString(); // Create listview item ListViewItem lvItem = new ListViewItem("", icon); lvItem.SubItems.Add("ZAP: " + name); lvItem.SubItems.Add(data); lvItem.ToolTipText = item.ToString(); lvItem.Group = listView_main.Groups[2]; // ZAP group is index 2 // Find location of listview item to be replaced ListViewItem old_item = listView_main.FindItemWithText("ZAP: " + name, true, 0); // If item exists if (old_item.Index >= 0) { // Insert listview item listView_main.Items.Insert(old_item.Index, lvItem); // Remove old item listView_main.Items.RemoveAt(old_item.Index); } else { // Insert listview item listView_main.Items.AddRange(new ListViewItem[] { lvItem }); } } } I have a similar method that updates a debug window... And that works fine... Can anyone help??? Thanks in advance, Phil

      "Rules are for the obedience of fools and the guidance of wise men"

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Have you set a breakpoint to work out exactly which line throws the error ?

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups