vinoth kumar

vinoth kumar

  • NA
  • 23
  • 48.7k

listview item is add to textbox

Oct 3 2012 7:33 AM
Hi
  i want listview values is add to text box..this is my coding .

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Collections;
using System.DirectoryServices;
using System.Runtime.InteropServices;


namespace p2p
{
  public partial class Home : Form
  {

  List<object> AiSocket = new List<object>();

  delegate void additem(object obj);

  delegate void additem1(string str);

  public Home()
  {
  InitializeComponent();
  }

  private void button1_Click(object sender, EventArgs e)
  {
  this.label3.Text = "Collecting Information...";
  try
  {

 

  if (this.textBox1.Text.Trim() == "")
  {
  MessageBox.Show("The Work Group name Should Not be Empty");
  return;
  }


  // Use Your work Group WinNT://&&&&(Work Group Name)
  DirectoryEntry DomainEntry = new DirectoryEntry("WinNT://" + this.textBox1.Text.Trim());
  DomainEntry.Children.SchemaFilter.Add("computer");


  // To Get all the System names And Display with the Ip Address
  foreach (DirectoryEntry machine in DomainEntry.Children)
  {
  string[] Ipaddr = new string[3];
  Ipaddr[0] = machine.Name;

  System.Net.IPHostEntry Tempaddr = null;

  try
  {
  Tempaddr = (System.Net.IPHostEntry)Dns.GetHostByName(machine.Name);
  }
  catch (Exception ex)
  {
  MessageBox.Show("Unable to connect woth the system :" + machine.Name);
  continue;
  }
  System.Net.IPAddress[] TempAd = Tempaddr.AddressList;
  foreach (IPAddress TempA in TempAd)
  {
  Ipaddr[1] = TempA.ToString();

  byte[] ab = new byte[6];
  int len = ab.Length;

  // This Function Used to Get The Physical Address
  int r = SendARP((int)TempA.Address, 0, ab, ref len);
  string mac = BitConverter.ToString(ab, 0, 6);

  Ipaddr[2] = mac;
  }

  System.Windows.Forms.ListViewItem TempItem = new ListViewItem(Ipaddr);


  this.ListHostIP.Items.Add(TempItem);
  }

  this.label3.Text = "Displayed";
  }
  catch (Exception ex)
  {
  MessageBox.Show(ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK);
  Application.Exit();
  }
  } 
 
 
  private void button2_Click(object sender, EventArgs e)
  { 
  textBox2.Text = ListHostIP.SelectedItems;
  }