Mitja Bonca 557 Nearly a Posting Maven

Do you talk about DataTables, or do you mean table in database?
In any case you surely can insert only two values (into two columns out of four columns).

Mitja Bonca 557 Nearly a Posting Maven

You cad do it like:

string answare = "j";
bool again = (answare == "j" || answare == "J") ? true : false;

about your issue: as ddanbe explained, (') is a type char, and I presume that variable answare is a type string ("). So these two will no go along. Or use one or the other.

This is a short version where you can choose between true of false.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

They sure (those two variable members; row_count, columnCount) do not exist in the scope. How does the compiper go through?
Where do you instanitate these two varibles? For sure not in the code you pasted up here. What they represent and which values they should have?

Please double check where do you do:

//this means to instanitate the variable:
int row_count= xx; //xx is some value
int columnCount = xx;  //xx is some value

Mitja

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

In this case, you have to:
1. get the data out of the file
2. read the data from the file, and check if the value exists do not insert (duplication are missed out), if the value do not exist, insert it into a file.

Or there is another way. Pass the data, which you have already saveed into a file, into some collection object, like an array or generic list, which will suit as the same thing as reading the file and checking which values has been inserted into a file.
When you will want to save the values from listBox for the 2nd time, you wil check is the value is or is not in the list. If is not the value will be instered into the fiel, and vice versa.

PS: And if you want to use this same file many times, the 1st thing when opening the project is to get the values out of the file, and save them into a list. So when the values from listBox will be ready to save into a file, will go again through the checking if every value exists in the list (if not, value can be inserted into a file).

I hope you understand the point here.
Mitja
Only this way you can salve this issue.

Mitja Bonca 557 Nearly a Posting Maven

Anytime. Just dont forget to close the thread and mark is as answered.
best regards,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Are you inserting into database, ot selecting from it? Regarding on your code (when using ExecuteNonQuery() method) you are inserting.

You have to change your format that will suit to the database` dateTime column format. You can do it like:

DateTime date = dateTimePicker1.Value.Date;
string sDate = date.ToString("dd-MM-yy", System.Globalization.CultureInfo.InvariantCulture);
DateTime dateInsert = Convert.ToDateTime(sDate); //use this dateInsert as parameter to insert into DB.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

No problem. I am glad I can help.
If the issue has been salved, simply mark the thread as answered or vote the post as helpful.

bye, bye
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Did you read my post?
I CANNOT help you if you wont cooperate. I was asking what exactly is the output - where does it come from? I cannot create a code, if I dont know what to do.
But thats your problem.
When you will explain exactly how and what you want, you can expect from us some help. I hope I was clear enough I cannot do the code from the data you gave us.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Try this code:

private void button1_Click(object sender, EventArgs e)
        {
            string path = @"C:\1\test21.txt";
            if (!File.Exists(path))
            {
                FileStream fs = File.Create(path);
                fs.Close();
            }

            using (TextWriter tw = File.AppendText(path))
            {
                foreach (string item in listBox1.Items)
                    tw.WriteLine(item);
            }
        }

This code addes (appends) the text from listBox to the file (which is being created for the 1st time automatically).

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

BTW: I have checked your wanted output, and found that there is not any single connection. Where from did you get those nubmers:
1 -> 2
1 -> 3
2 -> 1
2 -> 3
1 2-> 3
1 3-> 2
2 3-> 1

Please, be clear in explaining these result of yours.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

If you want to combine lists use "Union" extension:

private void SortedLists()
        {
            SortedList<string, string> sList1 = PopulateList1();
            SortedList<string, string> sList2 = PopulateList2();

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

Even if I still dont get you. Your output is in way different format then sortedLists them self.
Are you sure you are not only wanted to combine lists? But you want to get "How many times the Keys are duplicating"? Am I right?

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Would you mind showing the code?
The problem is becuase you have already opened the dataReader. For sure you have a loop and you are trying to open already opened dataReader.
Double check the code, if you do not find an error, please paste the code in here.

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

Try using FileOpenDialog method to choose the image, and then PictureBox control to show the image inside of it:

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

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog open = new OpenFileDialog();
                open.InitialDirectory = @"C:\";
                open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
                if (open.ShowDialog() == DialogResult.OK)
                {
                    pictureBox1.Image = new Bitmap(open.FileName);
                    pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
                }
            }
            catch (Exception)
            {
                throw new ApplicationException("Failed loading image");
            }
        }
    }

Hope it helps,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

This is surely again one of the school projects.
You have to create a win form from console.

Ok, I did your homework, and here`s the code:

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

        private void button1_Click(object sender, EventArgs e)
        {
            int intDrawersPerDesk = 0;
            int intAllDesks = 0;
            //1. checking if textBox of wood type is empty:
            string strWoodType = textBoxWoodType.Text;                       
            if (strWoodType != String.Empty)
            {
                //2. checking if its a number for number of desks
                if (int.TryParse(textBoxDrawsPerDesk.Text.Trim(), out intDrawersPerDesk))
                {
                    //3. checking if its a number for number of drawers
                    if (int.TryParse(textBoxAllDesks.Text.Trim(), out intAllDesks))
                    {
                        //4. calculations, and checking of any of the numbers are zero
                        int intAllDrawers = NumberOfDrawers(intDrawersPerDesk, intAllDesks);                        
                        if (intAllDrawers > 0)
                        {
                            //5. checking exact wood type
                            string strShortWoodType = WoodType(strWoodType);
                            if (strShortWoodType != "error")
                            {
                                float fTotal = CalculateTotalCost(strWoodType, intAllDrawers);
                                MessageBox.Show("The total code is " + fTotal + ".");
                            }
                            else
                                MessageBox.Show("Please enter the correct wood type (mahogany, oak or pine).");
                        }
                        else
                            MessageBox.Show("Sum of all drawers is zero. Please higher the number of desk or drawers.");
                    }
                }
            }
            else
                MessageBox.Show("Please enter the correct wood type.");
        }

        private int NumberOfDrawers(int intDrawersPerDesk, int intAllDesks)
        {
            return intDrawersPerDesk * intAllDesks;
        }

        public string WoodType(string strTreeType)
        {          
            switch (strTreeType)
            {
                case "mahogany":
                    {
                        strTreeType = "m";
                        break;
                    }
                case "oak":
                    {
                        strTreeType = "o";
                        break;
                    }
                case "pine":
                    {
                        strTreeType = "p";
                        break;
                    }
                default:
                    {
                        strTreeType = "error";
                        break;
                    }
            }
            return strTreeType;
        }

        private float …
Mitja Bonca 557 Nearly a Posting Maven

But to use Dictionary collection and especially the queries (using Linq) on it takes time (quite a lot of it). I am still rearing, but the progress is noticeable.
Dictionary is a very powerful "tool", which can come right in many occasions.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

No. Its not possible. Ok, it is, but then you run out of every order. So, no, better stay away of putting all into one ArrayList.

About my code, all is saved into arrayLists, just that all are gethered in the Dictionary( i.e: at index 0 there are bankDetails, at index 1 there are accDetails...).

But I guess you do not understand what I`m talking about dont you?
You will (later).
Mitja

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

Instead of using so many ArrayList, you can use Dictionary:

public partial class Form1 : Form
    {
        Dictionary<string, ArrayList> dic;
        public Form1()
        {
            InitializeComponent();
            comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
            CreateMain();
        }

        private void CreateMain()
        {
            dic = new Dictionary<string, ArrayList>();
            string[] array = { "bankDetails", "accDetails", "transDetails" };
            foreach (string item in array)
            {
                dic.Add(item, PopulateArrays(item));
                comboBox1.Items.Add(item);
            }
        }

        private ArrayList PopulateArrays(string value)
        {
            ArrayList aList = new ArrayList();
            if (value == "bankDetails")
            {
                aList.AddRange(new string[] { "a1", "a2", "a3" });
            }
            else if (value == "accDetails")
            {
                aList.AddRange(new string[] { "b1", "b2", "b3" });
            }
            else if (value == "transDetails")
            {
                aList.AddRange(new string[] { "c1", "c2", "c3" });
            }
            return aList;
        }

        private void comboBox1_SelectedIndexChanged(object obj, EventArgs e)
        {
            string item = comboBox1.SelectedItem.ToString();
            listBox1.Items.Clear();
            //this:
            var varItems = from d in dic
                           where d.Key == item
                           select d.Value;
            //or this:
            //var varItems = dic.Where(a => a.Key == item).Select(a => a.Value).ToList();
            foreach (ArrayList list in varItems)
                foreach (string str in list)
                    listBox1.Items.Add(str);
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

As SethWebster explained, you return an array.
If there are more value with different type (int, decimal, string, ...) you return an object array.
If there are all the values of the same type, you can return the same type:

public int[] Returnmethod()
{
    int a = 1;
    int b = 2;
    return new int[] {a , b };
}

Mitja

Mitja Bonca 557 Nearly a Posting Maven
TextBox[] tbs = new TextBox[] { textBox1, textBox2 };
decimal total = 0M;
for(int i = 0; i < tbs.Lenght; i++)
     total += ConvertToDecimal(tbs[i].Text);
Mitja Bonca 557 Nearly a Posting Maven

Maybe you can use Form_Load event hanlder, or overriden OnShow.

Mitja Bonca 557 Nearly a Posting Maven

Check out this code:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.Columns.Add("col1", "Column 1");
            dataGridView1.Columns.Add("col2", "Column 2");
            DataGridViewCheckBoxColumn column3 = AddingCheckBoxColumn();
            dataGridView1.Columns.Add(column3);

            for (int i = 1; i < 10; i++)
                dataGridView1.Rows.Add(i, "Item " + i, false);

        }

        private DataGridViewCheckBoxColumn AddingCheckBoxColumn()
        {
            DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
            {
                column.HeaderText = "Column3";
                column.Name = "col3";
                column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                column.FlatStyle = FlatStyle.Standard;
                column.ThreeState = true;
                column.CellTemplate = new DataGridViewCheckBoxCell();
                column.CellTemplate.Style.BackColor = Color.White;
            }
            return column;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                DataGridViewCheckBoxCell check = row.Cells["col3"] as DataGridViewCheckBoxCell;
                if (Convert.ToBoolean(check.Value) == true)
                    row.DefaultCellStyle.BackColor = Color.Yellow;
            }
        }
    }

It works, and I hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Check this out:

SortedList<int, int> sList = new SortedList<int, int>();
            int[] arrayKey = { 12, 13, 14, 23, 24, 34, 12, 13, 14, 23, 24, 34 };
            int[] arrayValue = { 1, 1, 1, 1, 1, 1, 2, 3, 3, 2, 2, 3 };

            for (int i = 0; i < arrayKey.Length; i++)
            {
                if (sList.ContainsKey(arrayKey[i]))
                    sList[arrayKey[i]] = arrayValue[i];
                else
                    sList.Add(arrayKey[i], arrayValue[i]);
            }

            sList.OrderBy(a => a.Key).ToList();

I did an example code to populate the sorted list, and the correct way how to do it.
Hope it helps,
Mitja

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

Just one think: What will happen with characters P in your case? There are two P letters in your word, so which index will be chosen for it?
This is not a good way to contiune. Just to make you think a bit better.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Or this one:

static void Main()
        {            
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            string proc = Process.GetCurrentProcess().ProcessName;
            Process[] processes = Process.GetProcessesByName(proc);
            if (processes.Length > 1)
            {
                MessageBox.Show("Application already running...", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

No, you have to put the instance of the Random on the class level, then you will not have problems with getting random number every where (on load event, or on some button click event, or in some method):

//form1 class:
Random r = new Random();
public Form1()
{
    //constructor of form1
    IntializeComponent();
    int a = r.Next(100,201);  //for example!
    MessageBox.Show(a.ToString());
}

private void  button1_Click()
{
   int myNumber = r.Next(0,101); //for example!
   MessageBox.Show(myNumber.ToString());
}

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Do you talk about sql query or...?
If so, this is it:

string query = @"SELECT * FROM MyTable WHERE StartTime >= @start AND EndTime <= @end";
            //pass the parameters to @start and @end time
Mitja Bonca 557 Nearly a Posting Maven

damn, what a mess. Why dont you use stored procedure? You will get rid of these looong code. And some work on optimizing the sql query will surely do the trick.
I cannot even see what is all about this strange query, so hard to tell what cound be wrong for slow work.
As said, use stored procedures ( seperate all of them, insert, update, select), and do as little work as possible at ones.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Instead of using DataGridViewImageColumn use DataGridViewTextBoxColumn with ReadOnly property set to true. When you wish to show an image in the cell use following code:

DataGridViewImageCell iCell = new DataGridViewImageCell();
iCell .Value = myImage; //image value
dataGridView1[columnIndex, rowIndex] = iCell;

.. or:
http://www.daniweb.com/software-development/csharp/threads/339535

Mitja Bonca 557 Nearly a Posting Maven

Try this one:

string path = @"C:\1\testFile.txt";
            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
            {
                using (TextWriter tw = new StreamWriter(fs))
                {
                    //use tw variable to do writing!
                }
            }
Mitja Bonca 557 Nearly a Posting Maven

Take a look at this code I made some days ago. It gets the images from DB into ImageList:

List<ImageList> list;

        public Form1()
        {
            InitializeComponent();
        }

        private void buttonLoad_Click(object sender, EventArgs e)
        {
            list = new List<ImageList>();
            using (SqlConnection sqlConn = new SqlConnection("connString"))
            {
                string query = String.Format(@"SELECT PictureName, MyImage FROM Images");
                SqlCommand cmd = new SqlCommand(query, sqlConn);
                cmd.Connection.Open();
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ImageList _image = new ImageList();
                        _image.imageName = (string)reader[0];
                        byte[] data = (byte[])reader[1];
                        using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data))
                        {
                            Image image = new Bitmap(ms);
                            _image.imagePicture = image;
                            list.Add(_image);
                        }
                    }
                }
            }
            if (list.Count == 0)
                MessageBox.Show("There are no pictures in the database.");
        }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Why you dont use a Dictionary?
With:

Dictionary<int, List<int>> dic;
 //1st part is a key, 2nd part (generic list) are values
Mitja Bonca 557 Nearly a Posting Maven

You only instantiated TextBox, but its not created yet.

Mitja Bonca 557 Nearly a Posting Maven

When you open form2, pass a parameter of dateTimePicker (a value of it) in constructor to form2. So now you have both values on forms. You only get a value of dateTimePicker from form2 and compare them.

Mitja Bonca 557 Nearly a Posting Maven

Check this code I did a couple of weeks ago. The pictues are retreived from DB and shown in listbox:

List<ImageList> list;
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonLoad_Click(object sender, EventArgs e)
        {
            this.listBox1.Items.Clear();
            list = new List<ImageList>();
            using (SqlConnection sqlConn = new SqlConnection(connString))
            {
                string query = String.Format(@"SELECT PictureName, MyImage FROM Images");
                SqlCommand cmd = new SqlCommand(query, sqlConn);
                cmd.Connection.Open();
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ImageList _image = new ImageList();
                        _image.imageName = (string)reader[0];
                        byte[] data = (byte[])reader[1]; //be careful here number 1 is 2nd column in DB (1st is picName, 2nd is Image)
                        using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data))
                        {
                            Image image = new Bitmap(ms);
                            _image.imagePicture = image;
                            list.Add(_image);
                        }
                    }
                }
            }
            if (list.Count == 0)
                MessageBox.Show("There are no pictures in the database.");
            else
                ShowImagesAndList();
        }

        private void ShowImagesAndList()
        {
            foreach (ImageList image in list)
                this.listBox1.Items.Add(image.imageName);
        }
Mitja Bonca 557 Nearly a Posting Maven

This is what I have in mind:

List<Form> list = new List<Form>();
            foreach(Form form in Application.OpenForms)
            {
                if (form.Name != "Form1")
                    list.Add(form);
            }
            for (int i = 0; i < list.Count; i++)
                list[i].Close();

Sorry for that, I completely forgot. My mistake.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I see. Yes, You will have to create a list of forms which you want to close. after the loop will go through, you will loop again throug the list of opened forms. And then you will close them.

Mitja Bonca 557 Nearly a Posting Maven

Sure it does. You can write like:

if (form.Name != "Form1" && form.Name != "Form2") //and so on!
{
    //code
}
Mitja Bonca 557 Nearly a Posting Maven

oh. You want an Exception message? You can only have Exception message on try, catch block (only on catch actually).
I doubt here is possible do it so. But you can write your own, like you did above; just write a messageBox with your own description.

Mitja Bonca 557 Nearly a Posting Maven

Try this code, and let me know it the "file not found" message appears:

if (dataReader.Read())
    label1.Text = dataReader["energy_kcal"].ToString();
else
    MessageBox.Show("ITEM NOT FOUND."); // item not found error i-m-i-t-a-tion !

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Check out this code:

private void buttonWrite_Click(object sender, EventArgs e)
        {
            List<string> list = new List<string>(new string[] { "a,", "b", "c" }); //out put example
            CreateAndWriteIntoFile(list);
        }

        private void buttonRead_Click(object sender, EventArgs e)
        {
            List<string> list = ReadFromFile();
        }

        private void CreateAndWriteIntoFile(List<string> list)
        {
            string path = @"C:\MyFolder\myFile.txt";
            using (FileStream fs = new FileStream(path, FileMode.CreateNew))
            {
                //now when file is created you can write into it:
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    foreach (string name in list)
                        sw.WriteLine(name);
                }
            }
        }

        private List<string> ReadFromFile()
        {
            string path = @"C:\MyFolder\myFile.txt";
            List<string> list = new List<string>();
            using (StreamReader sr = new StreamReader(path))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                    list.Add(line);
            }
            return list;
        }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Simple. There is no data under the energy column, which would equal to the product (selected item).

Mitja Bonca 557 Nearly a Posting Maven

LOOK: Form1 CAN NOT BE CLOSED by any means! Do you got that?
You can open and close all other forms as much as you like, but not form1. As i have explained (I dont know how many time I will have to) before, when Form1 is closed, that means that whole application will close. Are we clear now?

About your third form.
Ok, when pressing button on form3, you can close form3 and form2 (do you mean Close or Hide - its a big difference?).

You can loop through Opened forms, and close them all (except Form1):

//on form3:
void buttonCloseAll_Click()
{
    foreach (Form form in Application.OpenForms)
    {
        if (form.Name != "Form1")
             form.Close();
    }
}

This code will close so far Opened forms (except Form1).
I hope we are clear now.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

My form3 has a button that when clicked will close itself, form1 and form2.

What is that suppose to mean?
I think it means to close it self (so form3), and close form1 and form2. So close all.
If this is not it, please give me a better explanation. Be more clear about what you really want.Thx
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Hi,
would you mind pasting some of the code in here? So we can see what is going wrong?
thx
Mitja