Click here to Skip to main content
15,911,711 members
Home / Discussions / C#
   

C#

 
GeneralRe: HttpWebRequest Pin
dummy461310-Mar-09 5:19
dummy461310-Mar-09 5:19 
GeneralRe: HttpWebRequest Pin
Curtis Schlak.10-Mar-09 5:49
Curtis Schlak.10-Mar-09 5:49 
GeneralRe: HttpWebRequest Pin
dummy461310-Mar-09 6:02
dummy461310-Mar-09 6:02 
GeneralRe: HttpWebRequest Pin
Curtis Schlak.10-Mar-09 6:24
Curtis Schlak.10-Mar-09 6:24 
QuestionHow to access checkbox control, which is in Datagrid view Pin
kumar_man10-Mar-09 1:11
kumar_man10-Mar-09 1:11 
AnswerRe: How to access checkbox control, which is in Datagrid view Pin
Xmen Real 10-Mar-09 2:31
professional Xmen Real 10-Mar-09 2:31 
Question.Net default proxy setting Pin
George_George10-Mar-09 0:53
George_George10-Mar-09 0:53 
QuestionObject reference not set to an instance of an object Pin
mrithula810-Mar-09 0:48
mrithula810-Mar-09 0:48 
Hi I have changed the code.When i debug this code im getting "Object reference not set to an instance of an object"..But then the output form window opens with the controls.The required output is not obtained..Im trying to list all the files in a folder in the ListView control..Please help me with this
using System;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Text;
using System.Xml;
namespace Windows21
{
    public class ListView1 : Form
    {
        XmlTextReader reader;
        XmlDocument doc = new XmlDocument();
        ListView listView = new ListView();
        Button button1 = new Button();
        ListBox listBox1 = new ListBox();

        public ListView1()
        {
            //listView.Dock = DockStyle.Fill;
            listView.Location = new Point(250, 250);
            listView.Width = 250;
            listView.Height = 100;
            button1.Visible = true;
            listBox1.Visible = true;
            button1.Text = "button1";
            button1.Location = new Point(100, 100);
            listBox1.Location = new Point(100, 150);
            PopulateListView();
            this.Controls.Add(listView);
            this.Controls.Add(button1);
            this.Controls.Add(listBox1);
            this.ClientSize = new Size(400, 200);
            button1.Click += new EventHandler(button1_Click);
        }

        private void PopulateListView()
        {
            try
            {
                // Set the view to show details.
                listView.View = View.Details;
                // Add columns
listView.Columns.Add("FileName", -2, HorizontalAlignment.Center);
                listView.Columns.Add("Status", -2, HorizontalAlignment.Left);
                  // Add items
                 reader = new XmlTextReader("path.xml");
               while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Text: //Display the text in each element.
                            //   Console.WriteLine(reader.Value);
                            String s1 = reader.Value;
                            String ss = listBox1.SelectedItem.ToString();
                            String sss = ss + s1;
                            object o3 = (object)sss;

                            DirectoryInfo dire = new DirectoryInfo(sss);
                            if (dire.Exists)
                            {
               String[] folder = Directory.GetDirectories(sss);
                                foreach (string foldername in folder)
                                {
              DirectoryInfo di = new DirectoryInfo(foldername);
                                    if (di.Exists)
                                    {
                String[] files = Directory.GetFiles(foldername);
                                        foreach (String filename in files)
                                        {
                                            FileInfo fil2 = new FileInfo(filename);
                           ListViewItem item1 = new ListViewItem();
                                            item1.Text = fil2.Name;
                                            item1.ImageIndex = 1;
                                            item1.Tag = fil2.FullName;
                         item1.SubItems.Add("Programming .NET");
                                            listView.Items.Add(item1);
                                   
                                        }}}}                           
                            break;
                    }}}
           
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.ClientSize = new System.Drawing.Size(756, 485);
            this.Name = "ListView1";
            this.ResumeLayout(false);    
    }
        private void button1_Click(object sender, EventArgs e)
        {
            //listBox1 lb = (listBox1)sender;
            string[] drives = Environment.GetLogicalDrives();
            // Loop into the string array
            foreach (string strDrive in drives)
            {
                // Add items (drives) to the list
                listBox1.Items.Add(strDrive.ToString());
            }}}}

AnswerRe: Object reference not set to an instance of an object Pin
Pete O'Hanlon10-Mar-09 1:00
mvePete O'Hanlon10-Mar-09 1:00 
AnswerRe: Object reference not set to an instance of an object Pin
NeCroFire10-Mar-09 1:03
NeCroFire10-Mar-09 1:03 
AnswerRe: Object reference not set to an instance of an object Pin
Rutvik Dave10-Mar-09 4:24
professionalRutvik Dave10-Mar-09 4:24 
GeneralRe: Object reference not set to an instance of an object Pin
mrithula811-Mar-09 19:18
mrithula811-Mar-09 19:18 
GeneralRe: Object reference not set to an instance of an object Pin
Rutvik Dave12-Mar-09 3:57
professionalRutvik Dave12-Mar-09 3:57 
GeneralRe: Object reference not set to an instance of an object Pin
fandikurnia6-Apr-09 21:10
fandikurnia6-Apr-09 21:10 
QuestionParsing "javascript-driven" webpage Pin
whaka10-Mar-09 0:30
whaka10-Mar-09 0:30 
QuestionIn use by another process Pin
abbd10-Mar-09 0:23
abbd10-Mar-09 0:23 
AnswerRe: In use by another process Pin
dan!sh 10-Mar-09 0:38
professional dan!sh 10-Mar-09 0:38 
AnswerRe: In use by another process Pin
Luc Pattyn10-Mar-09 0:42
sitebuilderLuc Pattyn10-Mar-09 0:42 
GeneralRe: In use by another process Pin
Xmen Real 10-Mar-09 2:36
professional Xmen Real 10-Mar-09 2:36 
QuestionRe: In use by another process Pin
abbd10-Mar-09 4:10
abbd10-Mar-09 4:10 
AnswerRe: In use by another process Pin
Xmen Real 10-Mar-09 4:12
professional Xmen Real 10-Mar-09 4:12 
QuestionRe: In use by another process Pin
abbd10-Mar-09 4:19
abbd10-Mar-09 4:19 
QuestionThrowing an exception in a constructor Pin
Rob Philpott9-Mar-09 23:47
Rob Philpott9-Mar-09 23:47 
AnswerRe: Throwing an exception in a constructor Pin
Eddy Vluggen10-Mar-09 0:02
professionalEddy Vluggen10-Mar-09 0:02 
GeneralRe: Throwing an exception in a constructor Pin
Rob Philpott10-Mar-09 0:05
Rob Philpott10-Mar-09 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.