CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Dec 2018
    Posts
    6

    Datagrid-forloop behavior

    Hello experts
    I have this behavior that I cannot figure it out. The following code is triggered by a button

    Code:
    try
    {
    
    Type typeFWPolicy2 = Type.GetTypeFromProgID("HNetCfg.FwPolicy2");
    INetFwPolicy2 fwPolicy2 = 				  (INetFwPolicy2)Activator.CreateInstance(typeFWPolicy2);
    
    foreach (INetFwRule rule in fwPolicy2.Rules)
    	{
    	lvItems.RuleName = rule.Name; ;
    	lvItems.RemoteAddress = rule.RemoteAddresses;
    	lvItems.Protocol = rule.Protocol.ToString();
    	lvItems.LocalPort = rule.LocalPorts;
    	dataGrid1.Items.Add(lvItems);
    	//MessageBox.Show("close me");
    }
    
    
    }
    catch (Exception ex)
    {
    
    MessageBox.Show("something went wrong");
    
    }
    When I run it, the datagrid is populated with the same record (first) entry that is repeated several times.
    then I added a Messagebox to troubleshoot, then Datagrid is populated correctly but I need to acknowledge each Messagebox !!!!. It is like it just needs that extra mouse click.
    any help is greatly appreciated
    Last edited by 2kaud; March 3rd, 2020 at 04:23 AM. Reason: Added code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured