Mitja Bonca 557 Nearly a Posting Maven

I did the whole code. There are now 2 forms. 1st one is like yours, and 2nd one is meant to add items.
Ok, here is a whole code:

//Form1:
    public partial class Form1 : Form
    {
        List<MyClass> list;
        public Form1()
        {
            InitializeComponent();

            //creating listView:
            listView1.Columns.Add("Item", 80, HorizontalAlignment.Left);
            listView1.Columns.Add("SubItem 1", 80, HorizontalAlignment.Left);
            listView1.Columns.Add("SubItem 2", -2, HorizontalAlignment.Center);
            listView1.View = View.Details;
            listView1.FullRowSelect = true;

            //create a new instance of a list<T>:
            list = new List<MyClass>();

            //populate list<T> (example code):
            AddingRows();

            //populating listView:
            ShowDataInListView();

            //creating comobBox`s event:
            this.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
            //some other event for adding and removing:
            this.buttonAdd.Click += new EventHandler(buttonAdd_Click);
            this.buttonRemove.Click += new EventHandler(buttonRemove_Click);
        }

        //EXAMPE CODE:
        private void AddingRows()
        {
            //some example population wtih 6 letters:
            string letters = "ABACADC";

            comboBox1.Items.Add("Show all");
            for (int i = 0; i < letters.Length; i++)
            {
                if (!comboBox1.Items.Contains(letters[i].ToString()))
                    comboBox1.Items.Add(letters[i].ToString());
                MyClass mc = new MyClass();
                mc.Item = "Item " + (i + 1);
                mc.SubItem1 = "SubItem " + (i + 1);
                mc.SubItem2 = letters[i].ToString();
                list.Add(mc);
            }            
        }

        //YOUR CODE TO ADD ROWS LATER ON:
        public void AddingRowsToList(string[] data)
        {
            //adding to list<T>:
            MyClass mc = new MyClass();
            mc.Item = data[0];
            mc.SubItem1 = data[1];
            mc.SubItem2 = data[2];
            list.Add(mc);

            //adding to comboBox if not exsits yet:
            if (!comboBox1.Items.Contains(data[2]))
                comboBox1.Items.Add(data[2]);

            //showing new data:
            ShowDataInListView();
        }

        private void ShowDataInListView()
        {
            listView1.Items.Clear();

            foreach (MyClass mc in list)
            {
                ListViewItem lvi = new ListViewItem(mc.Item);
                lvi.SubItems.Add(mc.SubItem1);
                lvi.SubItems.Add(mc.SubItem2);
                listView1.Items.Add(lvi);
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string comboSelection = (string)comboBox1.SelectedItem;
            listView1.Items.Clear();
            foreach (MyClass mc in list)
            {
                if (comboSelection …
Mitja Bonca 557 Nearly a Posting Maven

when ever i choose an item from the comboBox the listView will show only the items that there's subItem have the same text of the ComboBoxItem

Would you explain this a bit better? I dont have an idea of what you thing? Simply...

Mitja Bonca 557 Nearly a Posting Maven

From where do you get data?

Mitja Bonca 557 Nearly a Posting Maven

Do it this way:

Private NewMDIChild As frmReportProblem
Private Sub miReportProblem_Click(sender As System.Object, e As System.EventArgs)
	If NewMDIChild Is Nothing Then
		NewMDIChild = New frmReportProblem()
		NewMDIChild.MdiParent = Me
		NewMDIChild.Show()
	End If
End Sub
Mitja Bonca 557 Nearly a Posting Maven

Try this code, it works 100%:

private void WriteToFile()
        {
            string line = "-0.025 0.15 0.15 0.4 0.5 -0.05 0.1333333 0.2 0.4 0.5 -0.05 0.1333333 0.2 0.4 0.5 -0.05 0.1333333 0.2 0.4 0.5 -0.05 0.1333333 0.2 0.4 0.5";
            string path = @"C:\1\test27.txt";
            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
            {
                using (TextWriter tw = new StreamWriter(fs))
                {
                    string[] array = line.Split(' ');
                    string textToWrite = null;
                    for (int i = 1; i <= array.Length; i++)
                    {
                        if (i % 5 == 0 && i > 1)
                        {
                            textToWrite += array[i - 1];
                            tw.WriteLine(textToWrite);
                            textToWrite = null;
                        }
                        else
                            textToWrite += array[i - 1] + " ";
                    }
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Hello :)
in your 2nd example, the code will not get through. Code will compile, but will be an error on line 3). You will get an error "Object reference not set to an instance of an object.". Thats because a1 was not instantiated yet, and thats why you cannot reach "field" property (or field) on asd class (yet).

1st code looks defenatelly ok.

Mitja Bonca 557 Nearly a Posting Maven

That you can return T. Becuase the method is a return type of <T>. If there is no specific return type in the method name, you are unable to return it.

In your 2nd example you can return T vlaue, when in your 1st can not.

Mitja Bonca 557 Nearly a Posting Maven

Depends, if your return that type of not. If you do not return, then your method does not need to be a type of <T>, otherwise is has to be.
Example:

static List<T> GetInitializedList<T>(T value, int count)
    {
	// This generic method returns a List with ten elements initialized.
	// ... It uses a type parameter.
	// ... It uses the "open type" T.
	List<T> list = new List<T>();
	for (int i = 0; i < count; i++)
	{
	    list.Add(value);
	}
	return list;
    }

    static void Main()
    {
	// Use the generic method.
	// ... Specifying the type parameter is optional here.
	// ... Then print the results.
	List<bool> list1 = GetInitializedList(true, 5);
	List<string> list2 = GetInitializedList<string>("Perls", 3);
	foreach (bool value in list1)
	{
	    Console.WriteLine(value);
	}
	foreach (string value in list2)
	{
	    Console.WriteLine(value);
	}
    }
ddanbe commented: Good explanation. +9
Mitja Bonca 557 Nearly a Posting Maven

I would say there is no difference, just that the your 1st example shows to which property some value is relied to. But if you know what you are doing, and know code well, its surely better to use 2nd option, which is the same as 1st one, but faster to write (execution time is the same tho).

Mitja Bonca 557 Nearly a Posting Maven

Are you talking about generic method?
If the operations performed by several overloaded methods are identical for each argument type, the overloaded methods can be more compactly and conveniently coded using a generic method. You can write a single generic method declaration that can be called at different times with arguments of different types. Based on the types of the arguments passed to the generic method, the compiler handles each method call appropriately.

here is an example code:

static void Main( string[] args )
     {
         // create arrays of int, double and char
         int[] intArray = { 1, 2, 3, 4, 5, 6 };
         double[] doubleArray = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 };
         char[] charArray = { 'H', 'E', 'L', 'L', 'O' };
   
         Console.WriteLine( "Array intArray contains:" );
         PrintArray( intArray ); // pass an int array argument
         Console.WriteLine( "Array doubleArray contains:" );
         PrintArray( doubleArray ); // pass a double array argument
         Console.WriteLine( "Array charArray contains:" );
         PrintArray( charArray ); // pass a char array argument
      } // end Main
   
      // output array of all types
      static void PrintArray< E >( E[] inputArray )
      {
         foreach ( E element in inputArray )
            Console.Write( element + " " );
   
         Console.WriteLine( "\n" );
      } // end method PrintArray
  } // end class Generic method
vedro-compota commented: ++++++ +1
Mitja Bonca 557 Nearly a Posting Maven

Create a new DataTable and fill it up with the values from all those fields (in dataBase), using a correct query:

private void ShowData()
{
    int scheduledId = 1; //some example
    DataTable table = GetData(scheduledId);
    if(table.Rows.Count > 0)
    {
         //use data from dataTable to populate some contols, or dataGridView.
         //1. if controls, like textboxes
         foreach(DataRow dr in table.Rows)
         {
             textBox1.Text = dr[0].Tostring(); //index 0 is 1st column!
             //and so on...
         }

         //2. is you want to populate dataGridView, you can set table as a data source to dgv:
         //no need to create columns and stuff for dgv (it will create all automatically)
         dataGridView1.DataSource = new BindingSource(table, null);
    }
}
private DataTable GetData(int ScheduledEventID)
{
     SqlConnection sqlConn = new SqlConnection("connString");
     string query = @"Select * from ScheduledEvents where ScheduledEventID = @id";
     SqlCommand cmd = new SqlCommand(query, sqlConn);
     cmd.Parameters.Add("@id", SqlDbType.Int).Value = ScheduledEventID;
     SqlDataAdapter da = new SqlDataAdapter(cmd);
     DataTable table = new DataTable("MyTable");
     da.Fill(table);
     return table;
}

I hope this helps explaining how you get data and use them later in populating controls.

johnt68 commented: Always really helpful - thank you +1
Mitja Bonca 557 Nearly a Posting Maven

You can create as many constructors as you like. One can have no parameters, 2nd can have one, 3rd constructor can have 3 parameters and so on.
When you create a new instance of a class you then pass as many parameters as you have in those constructors. It will be called that constructor with the same number of parameters.

Can you clarify your statements from post 1 a bit better? I didnt understand it.

vedro-compota commented: +++++++ +1
Mitja Bonca 557 Nearly a Posting Maven

I changed my mind, I will rather use a dictionary. Its even better tool to use, and most important, you will not have n number of Lists (n = undefined).
This is the solutuion for you:

private void GetDataFromFile()
        {
            Dictionary<int, List<int>> dic = new Dictionary<int, List<int>>();
            string tag = "[HRData]";
            string path = @"C:\1\test26.txt";
            using (StreamReader sr = new StreamReader(path))
            {
                string line;
                int counter;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line != tag)
                    {
                        counter = 1;
                        string[] lineData = line.Split('\t');
                        foreach (string data in lineData)
                        {
                            int number = Convert.ToInt32(data);
                            if (!dic.ContainsKey(counter))
                                dic.Add(counter, new List<int> { number });
                            else
                                dic[counter].Add(number);
                            counter++;
                        }
                    }
                }
            }

            //getting data of sinlge column:
            StringBuilder sb = new StringBuilder();
            foreach (KeyValuePair<int, List<int>> kvp in dic)
            {
                var sum = kvp.Value.Sum();
                sb.AppendLine("Column " + kvp.Key.ToString() + ": " + sum.ToString());
            }
            MessageBox.Show("This is the result of summing all the columns:\n" + sb.ToString());
        }

I hope I will get a beer now :)

ddanbe commented: Cheers! Prosit! +9
Mitja Bonca 557 Nearly a Posting Maven

If you want to get together the data in individual column, you better create as many arrays (or even better generic lists) as you have columns. When you will read line by line, you put 1st value into 1st column, 2nd value into 2nd column, and so on.
On the end you will have (in your particular case) 6 arrays and you can easily do an average (sum all and divinde with the number of numbers).
As simple as that.

Mitja Bonca 557 Nearly a Posting Maven

I would stronglly reccomend, what has abelLazm proposed you, to change the event. Do not use SelectedIndexChaged, becuase you will have only problems. Use Click event.
What is the problem with SelectedIndexChnaged event is that it wires twice for the row selection. When you clik the listView for the 1st time it fires ones - thats ok, but as soon as you click it for the 2nd time, it will fire for the 1st clicked row, and for the 2nd time for the newly clicked row. So it can make your life very miserable, if oyur dont know how to handle it.

As said, use Click event and all will be fine - its the same thing.

I did an example code how to get items and subitems from lisrView:

public Form1()
        {
            InitializeComponent();

            listView1.Columns.Add("Column1", 100, HorizontalAlignment.Left);
            listView1.Columns.Add("Column2", -2, HorizontalAlignment.Center);
            listView1.View = View.Details;
            listView1.FullRowSelect = true;

            //add some example rows:
            for (int i = 1; i < 5; i++)
            {
                ListViewItem lvi = new ListViewItem(i.ToString() +".");
                lvi.SubItems.Add("Column 2 - " + i);
                listView1.Items.Add(lvi);
            }

            listView1.Click += new EventHandler(listView1_Click);
        }

        private void listView1_Click(object sender, EventArgs e)
        {
            string col1 = listView1.SelectedItems[0].Text;
            string col2 = listView1.SelectedItems[0].SubItems[1].Text;

            MessageBox.Show("1st column: " + col1 + "\n2nd column: " + col2);
        }
Mitja Bonca 557 Nearly a Posting Maven

This code is not so good. You have already opened Form1, and its not a good practice to create a new instance of Form1.
Better would be as I showed you, to pass an instance of form1 as parameter to the class, where you would like to use it,

private void button1_Click(object sender, EventArgs e)
        {
            OtherClass otherclass = new OtherClass(this);//ADDED this- its a instance of Form1
            NewThread = new Thread(new ThreadStart(otherclass.MyNewThread));
            NewThread.Start();
        }

////////////////////////
    public class OtherClass
    { 
        Form1 form1;
        //constructor:
        public OtherClass(Form1 _f1)
        {
          this.form1 = _f1;
        }
        public void MyNewThread()
        {
            Console.WriteLine("in OtherClass"); //my thread has started as this shows up in output            
            form1._UpdateLabel("New Text"); // This does not update the label text
        }
    }
Suzie999 commented: very very helpful info to a newb like me. +1
Mitja Bonca 557 Nearly a Posting Maven

If I understand you well, you would like to update a label on from1 from some other form, am I right?
For this you do not need delegates at all, and you do not need to start a new Thread either.
You can do it:

//form1:
public void UpdateLabel(string item)
{
    this.label1.Text = item;
}

//form2:
Form1 f1;
public Form2(Form1 _f1)
{
    //constructor of form2
    Initializecomponent();
    this.f1 = _f1;
}

private void button1_ClickUpdateLabelOnform1(objec sender, EventArgs e)
{
    f1.UpdateLabel("New text to pass to form1 form form2");
}

Thats it.

Mitja Bonca 557 Nearly a Posting Maven

Check out this code:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Image Files(*.png; *.jpg; *.bmp)|*.png; *.jpg; *.bmp";
            // Allow the user to select multiple images.
            open.Multiselect = true;
            open.Title = "Image browser";

            if (open.ShowDialog() == DialogResult.OK)
            {
                foreach (String file in open.FileNames)
                {
                    string fullfileName = System.IO.Path.GetFullPath(file);
                    string showFileName = System.IO.Path.GetFileName(file);

                    comboBox1.Items.Add(new ComboBoxItems { FullPath = fullfileName, FileName = showFileName });
                }
                comboBox1.DisplayMember = "FileName";
                comboBox1.ValueMember = "FullPath";
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string filePath = (comboBox1.SelectedItem as ComboBoxItems).FullPath;
            if (filePath != String.Empty)
            {
                pictureBox1.Image = new Bitmap(filePath);
                this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
            }
        }
    }
    class ComboBoxItems
    {
        public string FullPath { get; set; }
        public string FileName { get; set; }
    }
Mitja Bonca 557 Nearly a Posting Maven

And you would like to get which columns, and show them in dgv?
Use can fill DataTable with SELECT query, and bind dataTable to the dgv:

DataTable table = new DataTable();
//use sqlConnection and SqlCommand to create the command with this query:
sting query = @"SELECT tblItem.Id, tblItem.Name, tblItem.Price, tblItemType.Type FROM tblItem, tblItemType WHERE tblItemType.ID = tblItem.TypeID";
SqlConnection sqlConn = new SqlConnection("connString");
SqlCommand cmd =new SqlCommand(query, sqlConn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(table);
//bind data from dataTable to the dgv:
this.dataGridView1.DataSource = table;

This is it.

Mitja Bonca 557 Nearly a Posting Maven
comboBox1.Text

//an example code:
comboBox1.Items.AddRange(new string[] { "item 1", "item 2", "item 3" });
comboBox1.Text = "Select date";

property will do it ones again!
But I would like to ask you how do you populate data into comboBox?

Mitja Bonca 557 Nearly a Posting Maven

Would you please stop with the threads names as "Help,,!!". This is getting us no where. And please, stop posting double or even more same posts. All aobut these numbers.
Create one thread and hold to it!! I have answered on a couple of your threads, but NONE has been answered so far. So, I wont even help you out any longer, and I doubt any one will.

Please, get serious, get some books and study! Dont bother us here with every single homework, that you teacher gives it to you.
Sorry for sounding so harsh, but this is pis... me off slowely. This is just not the way to receive help, and a knowledge.

Mitja

ddanbe commented: Right! +9
Mitja Bonca 557 Nearly a Posting Maven

You have an error on row No.20. It should be like this:

dateTimePicker1.Value = Convert.ToDatetime(drr["BILL DATED"]);
ddanbe commented: Nice. +9
Mitja Bonca 557 Nearly a Posting Maven

As ddanbe said. I will only show an example:

DateTime dateNow = DateTime.Now;
            // I will add just an example dateTime:
            DateTime dateFromDataBase = new DateTime(2011, 3, 21);

            //comparing both dates:
            if (dateNow.Date == dateFromDataBase.Date)
            {
                //if both dates are equal do code in here:
            }
            else
            {
                //if not equal, do in here (if needed)
            }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

LOL... I got the code in my 1st attempt. No repairing it. Damn Im good :)

Here it is:

//form1:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(this);
            f2.Show();
        }

        public void SelectingText(string searchText, bool bSelectUp)
        {
           
            int position = textBox1.Text.IndexOf(searchText);
            if (position > 0)
            {
                if (bSelectUp)
                    textBox1.Select(position, (textBox1.Text.Length - position));
                else
                    textBox1.Select(0, (position + searchText.Length));
                textBox1.ScrollToCaret();
                textBox1.Focus();
            }
            else
                textBox1.DeselectAll();
        }
    }

//form2:
    public partial class Form2 : Form
    {
        Form1 f1;
        public Form2(Form1 _f1)
        {
            InitializeComponent();
            this.f1 = _f1;
            //select by defualt the up radio button (so one will always  be selected):
            radioButton1.Checked = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {            
            string value = textBox1.Text;
            bool bSelectUp = (radioButton1.Checked) ? true : false;
            f1.SelectingText(value, bSelectUp);
        }
    }

Hope it helps,
Mitja

Joey_Brown commented: thanks!! +1
Mitja Bonca 557 Nearly a Posting Maven

Hi,
what kind of reports? Crystal Reports, or some else?
You can find some help about Crystal Reports here (which are by best by far - in my opinion):
http://www.codeproject.com/KB/cs/CreatingCrystalReports.aspx
http://www.codeproject.com/KB/database/MySQLCrystal.aspx
http://www.codeproject.com/KB/cs/Dynamic_Crystal_Report.aspx

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I did an exampe with sortedList:

private Method()
        {
            Win32.AllocConsole();

            SortedList<string, string> sList1 = PopulateList1();
            SortedList<string, string> sList2 = PopulateList2();

            //get only values which are equal in both sortedLists:
            var difList = sList1.Intersect(sList2).Select(a => a.Value).ToList();
            foreach (var item in difList)
                Console.WriteLine(item);
            Console.ReadLine();
        }

        private SortedList<string, string> PopulateList1()
        {
            SortedList<string, string> sList1 = new SortedList<string, string>();
            for (int i = 0; i < 10; i++)
                sList1.Add("Key" + i.ToString(), "Value" + i.ToString());
            return sList1;
        }

        private SortedList<string, string> PopulateList2()
        {
            SortedList<string, string> sList1 = new SortedList<string, string>();
            for (int i = 6; i < 16; i++)
                sList1.Add("Key" + i.ToString(), "Value" + i.ToString());
            return sList1;
        }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Ok, sortedList, what is the Key are Value type? Even the Linq query can deffer a lot, depending on the types.
Is it somethink like: SortedList<string, string> or do you use any custom objects inside?

Mitja

ddanbe commented: Could not give rep to your next post so I do it here. +9
Mitja Bonca 557 Nearly a Posting Maven

DataSource is a property of some controls (like DataGridView) which is used for binding data to these Controls.

The best would be to look an example:

public partial class Form1 : Form
    {
        DataGridView dgv;
        DataTable table;
        BindingSource bs;
        public Form1()
        {
            InitializeComponent();
            
            dgv = new DataGridView();
            dgv.Location = new Point(20, 20);

            //this will always create a new row in the end of dgv:
            //when user will do insertion into new row of dgv, 
            //data will be automatically transfered to dataTable as well!
            dgv.AllowUserToAddRows = true;
            this.Controls.Add(dgv);
            CreatingDataSource();
        }

        private void CreatingDataSource()
        {
            table = new DataTable("myTable");
            table.Columns.Add("Id", typeof(int));
            table.Columns.Add("Name", typeof(string));
            //get some example data:
            table = GetData(table);
            //bind table to binding source:
            bs = new BindingSource(table, null);
            //bind binding source to dgv:
            dgv.DataSource = bs;
        }

        private DataTable GetData(DataTable table)
        {
            //my example data (I will add 2 rows):
            DataRow dr;
            for (int i = 1; i < 3; i++)
            {
                dr = table.NewRow();
                dr["Id"] = i;
                dr["Name"] = "name " + i;
                table.Rows.Add(dr);
            }
            return table;
        }
    }

Hope it helps,
Mitja

ddanbe commented: Good explanation! +9
Mitja Bonca 557 Nearly a Posting Maven

In win forms, you will have to specify the new position. The human eye recognize 25 pictures for second, so you will have to move the picture 25 times per second (per few inches every move).
In TimerTick event you have to execte the move. You can do your own method, which will be called from timerTick event. In this method you create some conditions, like when the object reaches XX,YY has to turn down, when object reaches XX,YY has to turn left, and so on... and on every step of the way you define a new location, which you then assign to the object (myObject.Location = new Point(XX, YY);).
Thats it.
Mitja

Mitja Bonca 557 Nearly a Posting Maven
Mitja Bonca 557 Nearly a Posting Maven

I did an example code which populates dgv from a dataSet, and then gets the selected row`s data, and passed them to form2`s textBoxes. In my example I only have 2 column in the dataSet (as in dgv of course) and 2 textBoxes to populate on form2.
Take a look, and let me know its any good.
Code:

//form1:
        DataSet ds;
        public Form1()
        {
            InitializeComponent();

            ds = new DataSet();
            DataTable table = new DataTable("myTable");
            table.Columns.Add("column 1", typeof(string));
            table.Columns.Add("column 2", typeof(int));
            DataRow dr;

            //creating some example data to populate dgv:
            for (int i = 0; i < 10; i++)
            {
                dr = table.NewRow();
                dr["column 1"] = "Some name " + (i + 1);
                dr["column 2"] = i * 2;
                table.Rows.Add(dr);
            }
            ds.Tables.Add(table);

            //set dgv:
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.AutoGenerateColumns = true;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //bind dataSet to dgv:
            dataGridView1.DataSource = new BindingSource(ds.Tables["myTable"], null);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<object> list = new List<object>();
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                foreach (DataGridViewCell cell in row.Cells)
                    list.Add(cell.Value);

            Form2 f2 = new Form2();
            f2.GetDataFromForm1(list);
            f2.Show(this);
        }
    }    

//form2:
//I have decided to create a new method, which will be called from form1 (instead of it, the data can be passed into the constructor of form2 in the same way).
    public partial class Form2 : Form
    {
        public Form2()
        {
            //constructor of form2
            InitializeComponent();
        }

        public void GetDataFromForm1(List<object> data)
        {
            textBox1.Text = data[0].ToString();
            textBox2.Text = data[1].ToString();
        }
    }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

For having images in the listView (on in some other control), best way is to use an ImageList. You put images inside, and from there show images in listView. For example, how to get images form a disc, send then to imageList and then to listView:

//for better accurecy you can you an OpenFileDialog class, in which you can set a filter to show only images (png, img, bmp...)
            DirectoryInfo dir = new DirectoryInfo(@"C:\MyPictures");
            foreach (FileInfo file in dir.GetFiles())
            {
                try
                {
                    this.imageList1.Images.Add(Image.FromFile(file.FullName));
                }
                catch
                {
                    MessageBox.Show("This is not an image file");
                }
            }
            this.listView1.View = View.LargeIcon;
            this.imageList1.ImageSize = new Size(32, 32);
            this.listView1.LargeImageList = this.imageList1;
            //or
            //this.listView1.View = View.SmallIcon;
            //this.listView1.SmallImageList = this.imageList1;
 
            for (int j = 0; j < this.imageList1.Images.Count; j++)
            {
                ListViewItem item = new ListViewItem();
                item.ImageIndex = j;
                this.listView1.Items.Add(item);
            }

Hope it give you an idea,
Mitja

AngelicOne commented: thanks +1
Mitja Bonca 557 Nearly a Posting Maven

Foreach is a loop. So you cannot assign it to read for one string.
You did like:

string a = "a";
foreach(string b in a){} //this is an error!

You have to do it like:

string[] array = {"a", "b"};
foreach(string b in array)
{
    //get each string seperated in here!
}

you can use an Array, a ListArray, a Genertic List - so something that has a collection! Not a string.
Hope it helps,
Mitja

ddanbe commented: Great explanation and solve abilities! +8
Mitja Bonca 557 Nearly a Posting Maven

Sure, you cannot show an array in a messageBox (its like putting a string array into stirng - cant do).
You have to get all values from an array into a string, then show it in messageBox:

string[] myname = new string[2];
            myname[0] = "Shahid";
            myname[1] = "Hussain";
            string items = null;
            for (int i = 0; i < myname.Length; i++)
                items += myname[i] + Environment.NewLine;
            MessageBox.Show("This is the list:\n" + items);

Hope it helps,
Mitja

yousafc# commented: He is best Developer +0
Mitja Bonca 557 Nearly a Posting Maven

Sure you cannot. This will not do:

for (int i = 0; i == length; i++)
 {
      lblWord.Text = lblWord.Text + "_";
 }

You have to do the loop which will go through it:

for (int i = 0; i < length; i++)
 {
      lblWord.Text += "_";  //this will do it too :)
 }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Something lke that?

private void method()
        {
            const int value = 5;
            string tag = "_";
            string item = "";
            for (int i = 0; i < value; i++)
                item += tag;
            MessageBox.Show("You have chosen " + value.ToString() + " underscores.\nThe result is: \"" + item + "\"");
        }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

In Program.cs class you call

Application.Run(new Form2());
Mitja Bonca 557 Nearly a Posting Maven

Why dont you simple paste the code in here? And add some of descrition about the issue?
Please... every one does that.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

To null, that means the dataTable is empty and it has no name (if you have specified it before filling it). So, it clears out.
Its like the same as you do:

DataTable table = new DataTable();

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Look at this code, it removes the duplications:

public partial class Form1 : Form
    {
        DataSet ds;
        public Form1()
        {
            InitializeComponent();
            CreatingDS();            
        }

        private void CreatingDS()
        {
            ds = new DataSet();
            DataTable table = new DataTable("MyTable");
            table.Columns.Add("id", typeof(int));
            table.Columns.Add("name", typeof(string));

            string[] names = { "A", "B", "C", "A", "B" };
            DataRow dr;
            for (int i = 0; i < names.Length; i++)
            {
                dr = table.NewRow();
                dr["id"] = i + 1;
                dr["name"] = names[i];
                table.Rows.Add(dr);
            }
            ds.Tables.Add(table);
            table = RemoveDuplicateRows(table, "name");

            comboBox1.DataSource = ds.Tables["MyTable"];
            comboBox1.DisplayMember = "name";
            comboBox1.ValueMember = "id";
        }

        public DataTable RemoveDuplicateRows(DataTable dTable, string colName)
        {
            Hashtable hTable = new Hashtable();
            ArrayList duplicateList = new ArrayList();

            foreach (DataRow drow in dTable.Rows)
            {
                if (hTable.Contains(drow[colName]))
                    duplicateList.Add(drow);
                else
                    hTable.Add(drow[colName], string.Empty);
            }

            foreach (DataRow dRow in duplicateList)
                dTable.Rows.Remove(dRow);

            return dTable;
        }
    }

hope it helps,
Mitja

AngelicOne commented: thanks for combobox removal of dups! +1
Mitja Bonca 557 Nearly a Posting Maven

pArray is an array of custom object, in your case the Person is a class.
Array of cusom class means you have (will have) more then one Person. If there is more then one, you need to put them into an array for having them together.
Mitja

vedro-compota commented: ++++++++++ +1
Mitja Bonca 557 Nearly a Posting Maven

Did you check the whole code? The code works, I guess you didnt see the "Form2 f2;" variables on top of the constructor of form1.

public partial class Form1 : Form
    {
        [B]Form2 f2;[/B]
        public Form1()
        {
            InitializeComponent();
        }
 
        //open form2 someplace else!!
        //before calling event bellow!
        private void button2_Click(object sender, EventArgs e)
        {
            f2.UpdateFormColor();
        }
    }

The same goes if you have more forms open. Get all opened forms and create that same method on other forms, and call them:

public partial class Form1 : Form
    {
        [B]Form2 f2;
        Form3 f3;[/B]//you need to have this instances of the forms visible to all class so they can be used!
        public Form1()
        {
            InitializeComponent();           
        }

        private void SetColorToForms()
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.Name = "Form2")
                    f2.UpdateFormColor();
                else if(form.Name =="Form3")
                    f3.UpdateFormColor();
            }
        }
    }
johnt68 commented: Extremely helpful ... and patient - thank you. +1
Mitja Bonca 557 Nearly a Posting Maven

If your form is already opened:

//form1:
    public partial class Form1 : Form
    {
        Form2 f2;
        public Form1()
        {
            InitializeComponent();
        }

        //open form2 someplace else!!
        //before calling event bellow!
        private void button2_Click(object sender, EventArgs e)
        {
            f2.UpdateFormColor();
        }
    }

//form2:
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public void UpdateFormColor()
        {
            this.BackColor = Color.YellowGreen;
        }
    }

Hope it helps,
Mitja

ddanbe commented: Constant effort. +8
Mitja Bonca 557 Nearly a Posting Maven
private static void Test()
        {
            List<string> list = new List<string>() { "A", "B", "C" };
            IList<IList<string>> perms = Permutations(list);
            foreach (IList<string> perm in perms)
            {
                foreach (string s in perm)
                {
                    Console.Write(s);
                }
                Console.WriteLine();
            }
        }

        private static IList<IList<T>> Permutations<T>(IList<T> list)
        {
            List<IList<T>> perms = new List<IList<T>>();

            if (list.Count == 0)
                return perms; // Empty list.

            int factorial = 1;
            for (int i = 2; i <= list.Count; i++)
                factorial *= i;

            for (int v = 0; v < factorial; v++)
            {
                List<T> s = new List<T>(list);                
                int k = v;
                for (int j = 2; j <= list.Count; j++)
                {
                    int other = (k % j);
                    T temp = s[j - 1];
                    s[j - 1] = s[other];
                    s[other] = temp;

                    k = k / j;
                }
                perms.Add(s);
            }

            return perms;
        }

The printout from the Test method is:
CAB
CBA
BCA
ACB
BAC
ABC

Mitja Bonca 557 Nearly a Posting Maven

My this code:

while (reader.Read())
{
    if(reader.GetValue(0) != DBNull.Value)
        listAtt.Items.Add(reader.GetValue(0).ToString());
        //or better coding to get value:
        //listAtt.Items.Add((string)reader[0]);
}

This should do it.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

You can see into this example code how it has to be done:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Text[]  arrayOfText = new Text[3];
            string[] array = new string[] { "A", "B", "C" };
            
            //Adding int Text Array:
            for(int i=0;i<arrayOfText.Length;i++)
            {
                arrayOfText[i].someText = array[i];
            }

            //reading out of Text Array:
            foreach (Text _text in arrayOfText)
            {
                string myText = _text.someText;
            }
        }
    }

    public struct Text
    {
        public string someText { get; set; }
    }

and I hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Yes you do:

if(dataGridView1.Rows.Count > 0)
{
   //your code
}
AngelicOne commented: thanks +1
Mitja Bonca 557 Nearly a Posting Maven

Btw, jsut in case:
that you would wonder where to get File class (add a new namespace: System.IO).
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Hi,
You can use StreamReader to read rows, and the code will look like this:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<string> list = GetDataFromFile();
            richTextBox1.Clear();

            foreach (string item in list)
                richTextBox1.AppendText(item + Environment.NewLine);
        }

        private List<string> GetDataFromFile()
        {
            List<string> list = new List<string>();
            string tag = "[HRData]";
            bool bGetText = false;
            string path = @"C:\1\test17.txt";
            using (StreamReader sr = new StreamReader(path))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (bGetText)
                        list.Add(line);
                    else if (line == tag)
                        bGetText = true;
                }
            }
            return list;
        }
    }

The problem is, especially if you want to show numbers in some kind of columns, a better idea would be to use a datagriview - to seperate numbers. This is just an idea.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

I will only add to ddanbe` post:
If you are not in some dgv`s event handler you get the row number like:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex1 = e.RowIndex;
            int rowIndex2 = GetRowIndex();
        }

        private int GetRowIndex()
        {
            int rowIndex = this.dataGridView1.CurrentCell.RowIndex;
            return rowIndex;
        }

Mitja

ddanbe commented: Thanks for the addition! +8