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. Windows Forms
  4. Problem in accessing an event of a user control from another in Win Forms

Problem in accessing an event of a user control from another in Win Forms

Scheduled Pinned Locked Moved Windows Forms
helpcssdatabasewinformsdata-structures
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.
  • U Offline
    U Offline
    User 462384
    wrote on last edited by
    #1

    Hi Guys, I am having an issue with the Windows User Contol communication. I am creating a winform application. I have a tree view in the page (UC1). I am populating data to that from DB. on the leaf node select, i have to call an even in a Grid (User Control2) which will populate the data depending on the selection of the treenode text. Here the Tree & Grid are usercontrols. I have tried to use events for doing the same. But there are issue, If any one can help me, i will be thankful to them Hi Guys, Thanks for your response. This is what i am trying to do. GridUser Control.cs public partial class LogGridViewUserControl : UserControl { public delegate void Data_Bind(object sender, LogGridEventArgs e); public event Data_Bind dataBindHandler; public LogGridViewUserControl() { InitializeComponent(); } public void OnDataBind(Object sender, LogGridEventArgs e) { if (dataBindHandler != null) { string str = CallBusiness(e.Connection); } } } public class LogGridEventArgs { public string Connection { get; set; } public LogGridEventArgs(string connection) { Connection = connection; } } TreeUserControl.cs public partial class TestTreeControl : UserControl { public TestTreeControl() { InitializeComponent(); // BuilTree() } private void trvTest_NodeSelect(object sender, TreeViewEventArgs e) { if (e.Node.Nodes.Count == 0) { I need to call the OnDataBind event in the Grid to populate the data in the Grid } } } In the main form, i will add the both user controls. How do i call the OnDataBind evnthandler of the GridView when a node selection is changed in the treeview. I am not an expert in the Winform development/ not so good with delegates. If any one can chip in, it will be of great help to me. Thanks Tutu

    R 1 Reply Last reply
    0
    • U User 462384

      Hi Guys, I am having an issue with the Windows User Contol communication. I am creating a winform application. I have a tree view in the page (UC1). I am populating data to that from DB. on the leaf node select, i have to call an even in a Grid (User Control2) which will populate the data depending on the selection of the treenode text. Here the Tree & Grid are usercontrols. I have tried to use events for doing the same. But there are issue, If any one can help me, i will be thankful to them Hi Guys, Thanks for your response. This is what i am trying to do. GridUser Control.cs public partial class LogGridViewUserControl : UserControl { public delegate void Data_Bind(object sender, LogGridEventArgs e); public event Data_Bind dataBindHandler; public LogGridViewUserControl() { InitializeComponent(); } public void OnDataBind(Object sender, LogGridEventArgs e) { if (dataBindHandler != null) { string str = CallBusiness(e.Connection); } } } public class LogGridEventArgs { public string Connection { get; set; } public LogGridEventArgs(string connection) { Connection = connection; } } TreeUserControl.cs public partial class TestTreeControl : UserControl { public TestTreeControl() { InitializeComponent(); // BuilTree() } private void trvTest_NodeSelect(object sender, TreeViewEventArgs e) { if (e.Node.Nodes.Count == 0) { I need to call the OnDataBind event in the Grid to populate the data in the Grid } } } In the main form, i will add the both user controls. How do i call the OnDataBind evnthandler of the GridView when a node selection is changed in the treeview. I am not an expert in the Winform development/ not so good with delegates. If any one can chip in, it will be of great help to me. Thanks Tutu

      R Offline
      R Offline
      RobCroll
      wrote on last edited by
      #2

      I'm not quite sure what you want but I think you may have it the wrong way around. Try creating a NodeSelected event in the TestTreeControl control and then fire the event where you need to call the OnDataBind method. Then in the main form subscribe to that event (see pseudo code below) MyTestTree.NodeSelected += new NodeSelectedDelegateHandler(MyTestTree_NodeSelected); void MyTestTree_NodeSelected(object source, LogGridEventArgs e) { MyLogGridViewUserControl.OnDataBind(source, e); } Also your LogGridEventArgs class should inherit from EventArgs Cheers

      Architecture is extensible, code is minimal.

      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