Mitja Bonca 557 Nearly a Posting Maven

Maybe you are dont use Linq namespace:

using System.Linq; //add this on the top of the class

Or you use 1.1 VS, becuase 2.0 has Linq included

Same solution would be :

dic[j]+= intValue;
Mitja Bonca 557 Nearly a Posting Maven

This was the code I did for him, and I used a Linq there (dont know why, just spontaniously I guess, even if your way is good the same way - just to assign new value to the appropriate key).

Is it working now? It surely was working before too. I tested it.

Mitja Bonca 557 Nearly a Posting Maven

Do this:

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

        private void button1_Click(object sender, EventArgs e)
        {
            MyClass mc = new MyClass();
            mc.MyMethod();
        }
    }

    public class MyClass
    {
        public void MyMethod()
        {
            System.Windows.Forms.MessageBox.Show("This is a message from my class.");
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

I showed you in the code I gave you in some other thread. I was using dictionary collection to get the values of the columns (and a sum of them).

Mitja Bonca 557 Nearly a Posting Maven

Here is the code you want. But I find it hard that you will underatand it:

string path = @"C:\1\";
            string[] file1_Lines = File.ReadAllLines(path + @"TraceSet.csv");
            string file2 = File.ReadAllText(path + @"SBoxOutput.csv");
            string[] file2_Lines = file2.Split(new string[]{"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
            
           //creating 2 lists for average values of file1 and file2:
            List<float> averageFile1 = new List<float>();
            List<float> averageFile2 = new List<float>();

            //filling list1 - with average calculation of the file1 (row average):
            foreach (string line in file1_Lines)
            {
                string[] columns = line.Split(';');
                float fAvg = 0f;
                for (int i = 1; i < columns.Length; i++)
                {
                    float value = Convert.ToSingle(columns[i]);
                    fAvg += value;
                }
                //get the average and add to list:
                fAvg = fAvg / (columns.Length - 1);
                averageFile1.Add(fAvg);
            }

            //filling list2 - with average calculation of the file2 (column average):
            //creating a dictionary collection for get the sum of values in the columns
            Dictionary<int, int> dic = new Dictionary<int, int>();
            for (int i = 0; i < file2_Lines.Length; i++)
            {
                string[] lineValues = file2_Lines[i].Split(';');
                for (int j = 0; j < lineValues.Length; j++)
                {
                    int intValue = Convert.ToInt32( lineValues[j]);
                    if (dic.ContainsKey(j))
                        dic = dic.ToDictionary(d => d.Key, d => d.Key == j ? d.Value + intValue : d.Value);
                    else
                        dic.Add(j, intValue);
                }
            }
            
            //get the average into the list2 from the dictionary:
            int rows = file2_Lines.Length;
            foreach (KeyValuePair<int, int> _value in dic)
            {
                averageFile2.Add(_value.Value / rows);
            }

            //
            //
            //subtract the average of row 1 from the average of column 1 and reapeat for each row and column 
            //
            List<float> newList = …
Mitja Bonca 557 Nearly a Posting Maven

then subtract the average of row 1 from the average of column 1
and reapeat for each row and column...

From which row, and from which column? Please be more specific!!!

Mitja Bonca 557 Nearly a Posting Maven

Not a good example, sorry. Why? No need to explaining.

Mitja Bonca 557 Nearly a Posting Maven

Im not sure where would you like to put the calulated value, but this is how to be done, and like you already did it:

foreach (string item in rowVals)
                    {
                        try
                        {
                            float num = float.Parse(item);
                            sum += num;
                            addedItems++;
                        }
                        catch (Exception)
                        {
                            //throw;
                        }
                    }

You have to get the other value (let say "num" is value A), value B. And the you subtract one from antoher. The value you will get, put into a new arraylist.

Btw, I know you have no idea how to do it, it would be best to show me how the csv file is made, so I can show you on the exmple code.

Mitja Bonca 557 Nearly a Posting Maven

It doesnt matter if are constant or not. As long as the value is a type of float (or decimal, or even some other math type), you can do marh operations over them.
So you only have to get two varibles, and do a substraction over them. New value will be saved into an array list (or where ever you want it).

Mitja Bonca 557 Nearly a Posting Maven

You type float (if you have decimals), or decimal:

float a = 0.564F;
 float b = 0.356F;
 float c = a - b;
Mitja Bonca 557 Nearly a Posting Maven

You will have to create a new object. Check it out here: http://www.codeproject.com/KB/buttons/RoundButton_csharp.aspx

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

ddanbe: my car has some problems too. But I am really not sure what to do now...
PS: I will stop answering on these kind of not-even-half-explined-threads.

Mitja Bonca 557 Nearly a Posting Maven

Hi Mitja,
Thanks for reply
Let's say I have 4 Databases listed on a combobox as [Movie,Books,Entertainment, and Games].

Wait...
Are these DataBases,... or
are these names of the tables in one dataBase?

Mitja Bonca 557 Nearly a Posting Maven

Was the post in any help? Iam not sure, because I was guessing what do you want to have. I was only assming, out of the table names you have me.

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

Whats the relation? Can you show me the code of it?

Mitja Bonca 557 Nearly a Posting Maven

You would like to get what?

Mitja Bonca 557 Nearly a Posting Maven

Heres an example:

List<Form> list = new List<Form>();
            foreach (Form f in Application.OpenForms)
                if (f.Name == "Form2")
                    list.Add(f);

            //close seleced (in this case only FindFrm will be closed:
            foreach (Form f in list)
                f.Close();

Maybe some forms do not have set the NAME propety. So you will have to set it manually in some place of form creation. Best it to put the code into "FormName.Designer" class:

//where is this code:
this.Text = "FindFrm";
//put this code too:
this.Name = "FindFrm";
Mitja Bonca 557 Nearly a Posting Maven

This is not a good way to close the form. You better do a loop of all forms, and then check which you want to select. Selected put into an array (pre-created), and when the code goes throught the loop (when it ends), go through the array of forms, and close them.
Array has to be created and put the forms inside, because you are not allows to change the state of the forms (in your case closing them) while in foreach loop. You will get an error.
Hope it helps explaing how to close opened forms.

Mitja Bonca 557 Nearly a Posting Maven

Hi,
Simple question.How do you rename a label?
I'm trying LAbel1.Name="sk";

Please someone tell me the correct code?

Why would you rename it? To use a Name property.
That is not only that you would like to set a new Text property for the label?
like:

label1.Text = My new text";

?
If you want to rename it, simpy do:

label1.Name = "NewName";
//check it:
string _name = label.1Name;
Mitja Bonca 557 Nearly a Posting Maven

So you have data in 2 DataTables? One is called Item, 2nd one is called ItemType.
Can you explain ones more a bit more clearly which data would you like to show in dgv?

Mitja Bonca 557 Nearly a Posting Maven

Check this out:

string value = "212132134214";
            char[] array = value.ToCharArray();
            StringBuilder sb = new StringBuilder();
            foreach (char str in array)
                sb.AppendLine(str.ToString());
            MessageBox.Show(sb.ToString());
Mitja Bonca 557 Nearly a Posting Maven

Here is some simple example how to use form and class:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string value = "ABC";
            NewClass nc = new NewClass(value);
            nc.MyMethod();
        }
    }

    public class NewClass
    {
        string classVariable;
        public NewClass(string parameter)
        {
            //constructor!
            string methodVariable = parameter;
            classVariable = methodVariable;
            //you can assign parameter directly to the classVariable!
        }

        public void MyMethod()
        {
            System.Windows.Forms.MessageBox.Show("This is a method in a new class, with the value: " + classVariable);
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Try it this way:

private void button1_Click(object sender, EventArgs e)
        {
            Label l = new Label();
            l.Location = new Point(100, 100);
            l.Text = "This is a text";
            this.Controls.Add(l);
        }
Mitja Bonca 557 Nearly a Posting Maven

Check this example:

ArrayList aList = new ArrayList();
            aList.Add("1 2");
            aList.Add("2 1");
            aList.Add("2 3 1");
            aList.Add("2 4 1 3");

            ArrayList aListNew = new ArrayList();
            //you have to create a new array list, because you cannot modify the list in the loop!
            foreach(string item in aList)
            {
                //creating a int array (generic list):
                List<int> intList = item.Split(' ').ToList().ConvertAll<int>(c => Convert.ToInt32(c));
                //sorting the list:
                intList = intList.Select(s => Convert.ToInt32(s)).OrderBy(o => o).ToList();
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < intList.Count; j++)
                {
                    if ((j + 1) < intList.Count)
                        sb.Append(intList[j].ToString() + " ");
                    else
                        sb.Append(intList[j].ToString());
                }
                aListNew.Add(sb);
            }
Mitja Bonca 557 Nearly a Posting Maven

Check this example:

string[] array1 = { "12345", "145", "1345" };
            string second= "23";
            int sum = 0;
            foreach (string item in array1)
            {
                if (item.Contains(second))
                    sum++;
            }
            MessageBox.Show("There is/are " + sum + " strings of \"" + second + "\" string in the array.");
Mitja Bonca 557 Nearly a Posting Maven

You some boolan flag. Like this:

bool bChecking;
        void textBox1_Leave()
        {
            if (!bChecking)
            {
                //put your code in the event in here!
            }
        }

        void YourCurrentMethod()
        {
            //do some code, which you want to do, and which fires Leave event of textBox!
            //just before the code fires the Leave event do:
            bChecking = true;
            //code...
            
            //and on the end set the flag back to false, so when the Leave event will be really called, it will be executed as well:
            bChecking = false;
            //and set the focus on textBox:
            textBox1.Focus();
        }
Mitja Bonca 557 Nearly a Posting Maven

It is executing from a newly created thread. But this kind of coding is useless. Why would you want to call a method from a method, and without doing anything on the 1st one. Ok, mabye this is just an example code, made for testings only.

Mitja Bonca 557 Nearly a Posting Maven

No, only the method you declate in the new thread creation.

Mitja Bonca 557 Nearly a Posting Maven

What you have to do is to select that quantity field and subtract 5. When you will select the value, you then have to do an update over that field with the new value (Field = Field -5).

Mitja Bonca 557 Nearly a Posting Maven

Did you see my example I did it for you? Thats the example you hav to follow.
You know, when you selected a doctor in the dataGridView, and the his name and Id is passed from that form to the main one (so backwards).
Check ans study that example. The answer lays there.

Mitja Bonca 557 Nearly a Posting Maven
using system;

public class Hello{
public static void main(){
console.WriteLine("Hello C# World :)");
}
}

Maybe the problem lies in the "console" keyword (Console class) because it is written wth small initial. You have to write it with a big initial, like "Console".

This works:

using System;

namespace Apr01Test1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello C# world.");
            Console.ReadLine();
        }
    }
}
Mitja Bonca 557 Nearly a Posting Maven

Maybe you have any parameter(s) in the constructor on form3 (form2). If you have it, and you dont need to pass any from form1 you do:

Form3 f3 = new Form3(null);
f3.Show();
Mitja Bonca 557 Nearly a Posting Maven

You dont need any constructor. At least if you open form2 from from1 (or form3 from form1).

Mitja Bonca 557 Nearly a Posting Maven

or:

double min = sortList.Min(x => x.Value);
Mitja Bonca 557 Nearly a Posting Maven

if i want whole row of list box selected item then????????

What would that mean?

Mitja Bonca 557 Nearly a Posting Maven

do:

//in button click event:
listBox1.Item.Add(textBox1.Text);

and for setting the text to other controls you do:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            radioButton1.Text = listBox1.SelectedItem.ToString();
            textBox1.Text = listBox1.SelectedItem.ToString();
            //and so on..
        }
Mitja Bonca 557 Nearly a Posting Maven

only u have to write.

comboBox1.Text="";

??

Mitja Bonca 557 Nearly a Posting Maven

If you use a dataSouce, you have to call the Selectedindex property and set it to -1, so no item from a dataSource will be choosen on the show.
Example.

string[] array = { "a", "b", "c" };
            comboBox1.DataSource = array;
            comboBox1.SelectedIndex = -1;
            comboBox1.Text = "Select date";
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

Wi, would you mind showing us the code, so we can see if there is something wrong with it?
thx

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

Get the states based on selected country to populate comboBox2:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            SqlDataAdapter da1 = new SqlDataAdapter("select State from States where country_name='" + combobox1.SelectedItem.ToString() + "'", "Data Source=.;Initial Catalog=master;Integrated Security=True;");
            da1.Fill(ds1);
            int i = ds1.Tables[1].Rows.Count;

            for (int s = 0; s < i; s++)
            {
                comboBox2.Items.Add(ds1.Tables[1].Rows[s][1]);
            }
        }

Then you geta all cities based on selected state:

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            SqlDataAdapter da1 = new SqlDataAdapter("select City_name from Cities where State_Name ='" + combobox2.Selecteditem.ToString() + "'", "Data Source=.;Initial Catalog=master;Integrated Security=True;");
            da1.Fill(ds1);
            int i = ds1.Tables[2].Rows.Count;

            for (int s = 0; s < i; s++)
            {
                comboBox3.Items.Add(ds1.Tables[2].Rows[s][1]);
            }
        }

Table for index 0 is for the Countries, table at index 1 is for the states, and table at index 2 is for the cities (table[0], table[1], table[2]).

Mitja Bonca 557 Nearly a Posting Maven

No problem. Just thread as answered (or vote as useful), to close the thread.
bye

Mitja Bonca 557 Nearly a Posting Maven

string (in database this would equal "varchar" - set it to 50 characthers lenght -thats enough

Mitja Bonca 557 Nearly a Posting Maven

You didnt even set the min value until here. It is still 0 (or not even that, because you didnt initialize it). So you cannot compare it (if(v > min)!

Mitja Bonca 557 Nearly a Posting Maven

use:

if(this.comboBox1.SelectedIndex > -1)
{
    this.comboBox1.Selecteditem.ToString();
    //or:
    this.comboBox1.Text;
    //or:
    this.comboBox1.GetItemText(this.comboBox1.SelectedItem);
}

one of these it should get the selected item

Mitja Bonca 557 Nearly a Posting Maven

Wrong. You have to put a property of a textbox control on the end of it to check it:

if(textBox.Text != String.Empty)
{
   //not empty (not null, even empty and null are not the same things)
}
else
{
   //empty!
}
Mitja Bonca 557 Nearly a Posting Maven

Create a try catch block arund cmd.ExecuteNonQuery(); method. This way you will see what is the problem:
DO:

try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
   MessageBox.Show(ex.Message);
}