Mitja Bonca 557 Nearly a Posting Maven

O`right, this will do it:

Public Sub New()
	InitializeComponent()
	listBox1.Items.AddRange(New Object() {2, 2, 2, 3, 13})
End Sub

Private Sub button2_Click(sender As Object, e As EventArgs)
	Dim list As New List(Of Integer)()
	For i As Integer = 0 To listBox1.Items.Count - 1
		Dim value1 As Integer = Integer.Parse(listBox1.Items(i).ToString())
		For j As Integer = i + 1 To listBox1.Items.Count - 1
			Dim value2 As Integer = Integer.Parse(listBox1.Items(j).ToString())
			If value1 = value2 Then
				list.Add(value1)
				RemoveItems(value1, i, j)
			End If
		Next
	Next

	'for the end, you do the math operations over the values:
	Dim result1 As Integer = 1
	For Each number As Integer In list
		result1 *= number
	Next
	Dim result2 As Integer = 1
	For i As Integer = 0 To listBox1.Items.Count - 1
		result2 *= Integer.Parse(listBox1.Items(i).ToString())
	Next

	MessageBox.Show("Variable 1 = " & result1 & vbLf & "Variable 2 = " & result2)
End Sub

Private Sub RemoveItems(value As Integer, a As Integer, b As Integer)
	For i As Integer = 0 To listBox1.Items.Count - 1
		If i = a Then
			listBox1.Items.RemoveAt(a)
		ElseIf i = b Then
			listBox1.Items.RemoveAt(b)
		End If
	Next
End Sub

Let me know if its working (it does here).

Mitja Bonca 557 Nearly a Posting Maven

2 - (Removed)
2 - (Removed)
2
3 - (Removed)
3 - (Removed)
3
4

If I understood, it should be like that:
Variable1 = 2 * 3
Variable2 = 3 (only 3 left)

----------------------------------
In your upper example there were 3 and 7 left, and you multiplay them and got 21!

Mitja Bonca 557 Nearly a Posting Maven

I did a code, but according to your last example this is not just it:

Take a look:

Public Sub New()
	InitializeComponent()
	listBox1.Items.AddRange(New Object() {2, 2, 3, 5, 5, 7})
End Sub

Private Sub button1_Click(sender As Object, e As EventArgs)
	Dim list As New List(Of Integer)()

	For i As Integer = 0 To listBox1.Items.Count - 1
		Dim value1 As Integer = Integer.Parse(listBox1.Items(i).ToString())
		For j As Integer = i + 1 To listBox1.Items.Count - 1
			Dim value2 As Integer = Integer.Parse(listBox1.Items(j).ToString())
			If value1 = value2 Then
				list.Add(value1)
				RemoveItems(value1)
			End If
		Next
	Next

	'for the end, you do the math operations over the values:
	Dim result1 As Integer = 1
	For Each number As Integer In list
		result1 *= number
	Next
	Dim result2 As Integer = 1
	For i As Integer = 0 To listBox1.Items.Count - 1
		result2 *= Integer.Parse(listBox1.Items(i).ToString())
	Next

	MessageBox.Show("Variable 1 = " & result1 & vbLf & "Variable 2 = " & result2)
End Sub

Private Sub RemoveItems(value As Integer)
	For i As Integer = 0 To listBox1.Items.Count - 1
		listBox1.Items.Remove(value)
	Next
End Sub
Mitja Bonca 557 Nearly a Posting Maven

And whai in case if you have numbers:
2,2,2,3,3,3,4

Mitja Bonca 557 Nearly a Posting Maven

You do not pass the parameters to the event.
If there is no actual parameters need, you can pass null, like:

private void but1_Click(object sender, EventArgs e)
{
    load.ClickHandler(null, null);
}
Mitja Bonca 557 Nearly a Posting Maven

Yee, look this code:

int intClicks;
        private void button1_Click(object sender, EventArgs e)
        {
            intClicks++;
            MessageBox.Show("button has been clicked " + intClicks + (intClicks == 1 ? " time." : " times."));
        }
Mitja Bonca 557 Nearly a Posting Maven

Would you mind telling me exactly what would you like to invert? I have no exact clue now, what you would you like to have. Thx in advance.

Mitja Bonca 557 Nearly a Posting Maven

How to invert?
From last to 1st? By which column (items, or subItems)?

I need more information.

Mitja Bonca 557 Nearly a Posting Maven

Becuase you cannot assign a null value to the Text property of the textBox.
You can do a checking if the value is null or not:

if(c.IDCardNumber != null)
     txtIDCardNo.Text = c.IDCardNumber.ToString();
else
     txtIDCardNo.Text = "";
Mitja Bonca 557 Nearly a Posting Maven

Forgot to say: You have to do an sql query to fill dataTable, but becuase I dont have this kind of dataBase, I filled it up by code (just example).

But what you really need it the 2nd part of the upper code.
bye

Mitja Bonca 557 Nearly a Posting Maven

Here is the working code:

Public Sub New()
	InitializeComponent()

	Dim ds As New DataSet()
	Dim table As New DataTable("MyTable")
	ds.Tables.Add(table)
	'my example columns creating and population:
	table.Columns.Add(New DataColumn("id", GetType(Integer)))
	table.Columns.Add(New DataColumn("code", GetType(String)))
	table.Columns.Add(New DataColumn("desc", GetType(String)))
	table.Rows.Add(1, "ADV", "ADVANCE")
	table.Rows.Add(2, "ADV", "ADVANCE")
	table.Rows.Add(3, "BUS", "BUS TICKET")
	table.Rows.Add(4, "BUS", "BUS TICKET")

	'create ListView:
	listView1.Columns.Add("Id", -2, HorizontalAlignment.Left)
	listView1.Columns.Add("Code", -2, HorizontalAlignment.Left)
	listView1.Columns.Add("Descriprion", -2, HorizontalAlignment.Left)
	listView1.View = View.Details
	listView1.FullRowSelect = True

	'do the selection of the dataTable:
	For Each dr As DataRow In ds.Tables("MyTable").Rows
		Dim bNewInsertion As Boolean = True
		For i As Integer = 0 To listView1.Items.Count - 1
			If dr(1).ToString() = listView1.Items(i).SubItems(1).Text Then
				bNewInsertion = False
				Exit For
			End If
		Next
		If bNewInsertion Then
			Dim lvi As New ListViewItem(dr(0).ToString())
			lvi.SubItems.Add(dr(1).ToString())
			lvi.SubItems.Add(dr(2).ToString())
			listView1.Items.Add(lvi)
		End If
	Next
End Sub
Mitja Bonca 557 Nearly a Posting Maven

Then you dont need to initialize it (it already is!).
All you have to do, is to pass the form`s reference (this):

//SomeConstructor(this)
{

}
Mitja Bonca 557 Nearly a Posting Maven

??
Yes? some resonable explanation?

Mitja Bonca 557 Nearly a Posting Maven

YOu can do it this way:

//form1:
        public Form1()
        {
            InitializeComponent();
            label1.Text = "";
        }

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

        public void PassDataFromForm2(decimal value)
        {
            label1.Text = value.ToString();
        }

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

        private void button1_Click(object sender, EventArgs e)
        {
            f1.PassDataFromForm2(numericUpDown1.Value);
        }
Mitja Bonca 557 Nearly a Posting Maven

Sure, you do not specify the table names. Look into my code, how I did it. I did named the dataTable, so it has a name, your do not have, because you fill dataTables (all togeter) in one stored procedure.

One more thing: the SqlDataAdapter will not look at the physical table names in your database to determine the table names in the ADO.NET DataSet. Sorry, there's really no way to do this automagically.

Why dont you create 3 sepersted stored procedures and use the code I did?

Mitja Bonca 557 Nearly a Posting Maven

How did your tables loose their names? Cant be?
If you do it right, the names will for sure stay (be there from the time of creation on...

YOu have to do code in C#, (create DataTable as well) and only call a storedProcedure (which only can include SELECT statement, nothing else), and fill in up:

DataSet ds = new DataSet();
        public Form1()
        {
            InitializeComponent();
        }

        private void GetData()
        {
            //DO THE SAME FOR EVERY SINLGE DATATABLE, LIKE THIS EXAMPLE:
            using (SqlConnection sqlConn = new SqlConnection("connString"))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "YourProcedureName";
                cmd.Connection = sqlConn;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable table = new DataTable("MyTable1");
                ds.Tables.Add(table);
                da.Fill(table);
            }
        }

        private void ReadData()
        {
            DataTable table = ds.Tables["MyTable1"];
            foreach (DataRow dr in table.Rows)
            {
                //code to get each value form dataTable goes here
            }
        }

If you will do anything different, you will surely look tables, or something else.

Mitja Bonca 557 Nearly a Posting Maven

Simple. YOu simply add a name in the brackets of the ds.Tables:

DataTable myTable = ds.Tables["table_passenger_details"];
Mitja Bonca 557 Nearly a Posting Maven

Did you think about something like this:
PS: code is meant to work with 2 forms (form2, and form3). If you want for, add 2 more.

public partial class Form1 : Form
    {
        Form[] forms;
        Form2 f2;
        Form3 f3;
        int counter;
        public Form1()
        {
            InitializeComponent();
            forms = new Form[] { f2, f3 };
        }

        private void buttonFor_Click(object sender, EventArgs e)
        {           
            if (counter < forms.Length)
            {
                CommonMethod();
                counter++;
            }
        }

        private void buttonBack_Click(object sender, EventArgs e)
        {
            if (counter > 0)
            {
                counter--;
                CommonMethod();               
            }
        }

        private void CommonMethod()
        {
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i] == null)
                {
                    if (i == 0)
                    {
                        f2 = new Form2();
                        forms[i] = f2;
                    }
                    else
                    {
                        f3 = new Form3();
                        forms[i] = f3;
                    }
                }
                if (counter == i)
                {
                    forms[i].Location = new Point((this.Location.X + this.Width + 10), this.Location.Y);
                    forms[i].Show();
                }
                else
                    forms[i].Hide();
            }
        }
    }

There is some work to be done, but this is working approximatelly.

Mitja Bonca 557 Nearly a Posting Maven

Hi, what is it that you would like to do exactly?

Mitja Bonca 557 Nearly a Posting Maven

I hope you are talking aobur DataTables. Simple name them by some uniqe name. If there is no other way, you can use numbers from 1 to 30 (as jockeyvn proposed), or use the name from sql table (table1, table2,table3 - if they are all different). Or use more sql table names, if there is any dataTable which has two or more sql tables (like: "... FROM Table1, Table2" - name dataTable as :Table1_Table2.

Remember its always good to name dataTables to something that you know what is in it (where it comes from). It easier to work. Thats why I would not recommend you to use numbers only.

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

I have finally understood what do you want, as soon as I have seen the form designer.
This is what I did for you:

namespace Apr23Test1
{
    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>:
            AddingRows();

            //populating listView:
            ShowDataInListView();

            //creating comobBox`s event:
            this.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
        }

        private void AddingRows()
        {
            //some example population wtih 6 letters:
            string letters = "ABACADC";
            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);
            }
        }

        private void ShowDataInListView()
        {
            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 == mc.SubItem2)
                {
                    ListViewItem lvi = new ListViewItem(mc.Item);
                    lvi.SubItems.Add(mc.SubItem1);
                    lvi.SubItems.Add(mc.SubItem2);
                    listView1.Items.Add(lvi);
                }
            }
        }
    }

    class MyClass
    {
        public string Item { get; set; }
        public string SubItem1 { get; set; }
        public string SubItem2 { get; set; }
    }
}

Will add some code to add and remove the items...
Mitja Bonca 557 Nearly a Posting Maven

Would you mind showing me an example? I have no clue about what you are talking about.
What subItems in comboBox? There is no subItems in comboBox.
I need an example code, with items and subItems.

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
Mitja Bonca 557 Nearly a Posting Maven

You have to get strings seperately from that control, and later join both into a dateTime:

string a = tpReservationDate.Value.ToLongDateString();
string b = tdtpEventTime.Value.ToLongTimeString();
DateTime date = Convert.ToDateTime(a + " " + b);

//Example:         
string a = "13.3.2011";
string b = "13:54:32";
DateTime date = Convert.ToDateTime(a + " " + b);
Mitja Bonca 557 Nearly a Posting Maven

To answer on your last question, you can easily do if you will use my code with a genric list:

private void button1_Click(object sender, EventArgs e)
        {
            //get 1. ip from the list (if there are many):
            textBox1.Text = list.Select(s => s.IPport).First();
            textBox2.Text = list.Select(s => s.Gate).First();
        }
Mitja Bonca 557 Nearly a Posting Maven

There is maybe a bit different approach, to use a generic list, which will save all the IPs and their gates.

List<MyIP> list;
        private void ReadFile_WithIP()
        {
            list = new List<MyIP>();
            using (StreamReader sr = new StreamReader(@"C:\YourFolder\YourFileName"))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] array = line.Split(':');
                    MyIP _ip = new MyIP();
                    _ip.IPport = array[0];
                    _ip.Gate = array[1];
                    list.Add(_ip);
                }
            }
        }

        internal class MyIP
        {
            public string IPport { get; set; }
            public string Gate { get; set; }
        }

To get all our your can do it:

foreach (MyIP _ip in list)
            {
                string _ipPort = _ip.IPport;
                string _gate = _ip.Gate;
            }
Mitja Bonca 557 Nearly a Posting Maven

So, does your code work like you want to?

Mitja Bonca 557 Nearly a Posting Maven

Lets clear some things now, and lets look into your example code:

DateTime dateOfEvent = Convert.ToDateTime(dtpReservationDate.Value.ToLongDateString());

You dont need to assign a method "ToLongDateString()", because you want to get a real DateTime value. And real dateTime value has nothing to do with the string date (or string time).
It would be enough to write:

DateTime dateOfEvent = dtpReservationDate.Value; //if this is some kind of dateTimePicker or monthCalendar
//if not, you do:
DateTime dateOfEvent = Convert.ToDateTime(dtpReservationDate.Value); //this should do it in the worst case scenario

... so you want now what exactly? I didnt get your question.
If you only want to pass the variable to another field or propery you can do:

DateTime dateTimeOfEvent = dateOfEvent;

Because every real DateTime value will have all (date and time). If this will not be possible to convert, you will get an error before that (in the upper code you pasted - for example).

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

What type is your list?
is it: List<double[]> ?

Mitja Bonca 557 Nearly a Posting Maven

I dont know what your list represents. So it would be good to add some code or explanation to the thread.

Check out my code I did yesterday here:
http://www.daniweb.com/software-development/csharp/threads/360495

As you can see Iam creating a dictionary, and use generic list<T> as Value.
This how you can get values of the columns together, and then you can do math operations over them.

Mitja Bonca 557 Nearly a Posting Maven

Check out this code. The 1st part is only a simple dgv population. Then is the code which color the rows:

public Form1()
        {
            InitializeComponent();
            dataGridView1.Columns.Add("col1", "column 1");
            dataGridView1.Columns.Add("col2", "column 2");
            dataGridView1.Rows.Add(1, "Canceled");
            dataGridView1.Rows.Add(2, "Ok");
            dataGridView1.Rows.Add(3, "Canceled");
            dataGridView1.Rows.Add(4, "Canceled");
            dataGridView1.Rows.Add(5, "Ok");

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (dataGridView1["col2", row.Index].Value != null)
                    if (dataGridView1["col2", row.Index].Value.ToString() == "Canceled")
                        row.DefaultCellStyle.BackColor = Color.Red;
            }
        }

It works.

Mitja Bonca 557 Nearly a Posting Maven

if you want to check if the value is not null:

while (r.Read())
{  
   if(r.GetValue(1) != DbNull.Value)
     string name = (string)r[1];
   //and so on for the rest of the fields...
}
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

What is wrong with this code? You only posted two methods, which can tell me nothing.
You have to be more precise about what do you want to achive.
Can you please do a bit better explanation, or add some more code? It would really help out.

Mitja Bonca 557 Nearly a Posting Maven

The "newNumbers" will be: 1,5 and 9.
I think this is what you have been looking for.

Mitja Bonca 557 Nearly a Posting Maven

Here you have an example code of multipidimensional array, and how to get values out of it:

int[,] array = new int[3, 4] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } };
            int[] newNumbers = null;
            for (int i = 0; i < array.GetLength(1); i++)
            {
                for (int j = 0; j < array.GetLength(0); j++)
                {
                    Array.Resize(ref newNumbers, (j + 1));
                    newNumbers[j] = array[j, i];
                }
                break;
            }
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

Instead of reading whole text, and then split the lines, you can get all lines into an array directly:

string[] lines = File.ReadAllLines(@"C:\file.txt");
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

My part:

string value ="some value";
 if (char.IsDigit(value[0]) && char.IsLetter(value[value.Length - 1]))
       value = "00" + value;