Mitja Bonca 557 Nearly a Posting Maven

Ok, if you still have any doubts about using button, let us know, ok?
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

Hi, would you mind describling your issue a bit better? I really dont understand what would you like to achive. But somehow I would say choosing Buttons for this task isnt the right option. Have you thought of what Momerath has proposed to you?
If you think differently, please go ahead and explain a bit mor precise.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Hi, it seems your connection string is not the right one. Have you checked here for it?
And are you sure about your parameters enters into connection string? Are defenatelly the right one?

Mitja Bonca 557 Nearly a Posting Maven

What is it that you want to split the string? Do you want to get all words into an array?

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

No it wont, unless if you have a whitespaces on both ends of the string. My upper code for sure does not have those white spaces. Double check your code for white spaces. If they are, remove them (or code will not insert them into a listBox).

btw, Where from you get that string?

Mitja Bonca 557 Nearly a Posting Maven

Do you want to use a MultiLine textBox? If so, here is your answer:

public Form1()
        {
            InitializeComponent();
            textBox1.Multiline = true;
            textBox1.ScrollBars = ScrollBars.Vertical;
            Method();
        }

        private void Method()
        {
            int[] array = { 1, 2, 3, 4, 5 };
            foreach (int value in array)
                textBox1.AppendText(value.ToString() + Environment.NewLine);
        }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

hey...i want to ask about how to convert string array to integer array. hope someone can help me.
thanks.

As long as the strings are only numbers (no commas or dots indside the string), you can convert the string into integer as Momerath shows abouve.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Sure it does. Check if you dont have any other code some place else. Delete dgv from the form (this will delete all its code) and put it back on the form (in form designer). And thats it - do nothing more. Use my code and it has to work - it did wok for sure for me.
Calling "ResizeRows()" method has to resize all the rows height to the wanted value (in my example is 30).
Hope it helps,
Mitja

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

Is this other forms already opened?

Mitja Bonca 557 Nearly a Posting Maven

There is a button "Mark as Answered" I think.

Mitja Bonca 557 Nearly a Posting Maven

So mark this thread as answered (cause i beleive it was) and start a new one -if necessary.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

This an example if you allow users to add rows, so even a new row will have the "default" height:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            dataGridView1.Columns.Add("col1", "Column1");
            dataGridView1.AllowUserToAddRows = true;

            //example data to populate:
            for (int i = 0; i < 10; i++)
                dataGridView1.Rows.Add("Cell " + i + 1);
            ResizeRows();
            //creating event for adding new rows:
            dataGridView1.RowsAdded+=new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
        }

        public void ResizeRows()
        {
            foreach (DataGridViewRow row in dataGridView1.Rows)
                row.Height = 30;
        }

        private void dataGridView1_RowsAdded(object obj, DataGridViewRowsAddedEventArgs e)
        {
            ResizeRows();
        }
    }

Hope it helps a bit,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Row height:

foreach (DataGridViewRow row in dataGridView1.Rows)
     row.Height = 30;
Mitja Bonca 557 Nearly a Posting Maven

Hi, I did an example code, which colors the textBox background, based on the correction of the letters inserted.
To test the code, you only put the textBox on the form, ther code takes care for the rese (even event creation).

PS: the word "tag" is the look which you are looking for!
Take a look:

public partial class Form1 : Form
    {
        bool bChecking;
        public Form1()
        {
            InitializeComponent();
            this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
        }

        private void textBox1_TextChanged(object obj, EventArgs e)
        {
            string tab = "fox";
            if (!bChecking)
            {
                bChecking = true;
                string written = textBox1.Text;
                if (written != String.Empty)
                {
                    if (written == tab)
                    {
                        textBox1.BackColor = Color.YellowGreen;
                        return;
                    }

                    int writtenLenght = written.Length;
                    try
                    {
                        string tabSelection = tab.Substring(0, writtenLenght);
                        if (written == tabSelection)
                            textBox1.BackColor = Color.Yellow;
                        else
                            textBox1.BackColor = Color.Red;
                    }
                    catch
                    {
                        textBox1.BackColor = Color.Red;
                    }
                }
                else
                    textBox1.BackColor = Color.White;
            }
            else
                bChecking = false;
        }
    }

Hope it helps a bit,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

You need to use delegate, look at this my example:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Feb27Exercise1
{
    public partial class Form1 : Form
    {
        System.Threading.Thread thread;
        delegate void TextBoxDelegate(string message);

        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            CreatingNewThread();
            while (thread.IsAlive)
                Application.DoEvents(); //waiting for termination!
            thread.Join();  //termninate thread!
        }

        private void CreatingNewThread()
        {
            int myValue = 40; //some value to pass as parameter to the other Thread
            OtherClass other = new OtherClass(this); //passing param to constructor 
            thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(other.SomethingToDo));
            thread.Start(myValue);
        }

        public void UpdatingTextBox(string msg)
        {
            if (this.textBox1.InvokeRequired)
                this.textBox1.Invoke(new TextBoxDelegate(UpdatingTextBox), new object[] { msg });
            else
                this.textBox1.Text = msg;
        }
    }

    public class OtherClass
    {
        Form1 form1;
        public OtherClass(Form1 _form1)
        {
            this.form1 = _form1;
        }

        public void SomethingToDo(object obj)
        {
            //I will create an example loop which, 
            //from which I will pass the value to textBox on form1 class:
            int myValue = Convert.ToInt32(obj);
            for (int i = 0; i < myValue; i++)
            {
                form1.UpdatingTextBox(i.ToString());
                //wait for a bit:
                System.Threading.Thread.Sleep(200);
            }
        }
    }
}

If it does not help, let me know, and dont forget to past some of your code in here -so that I can see whats it your problem, ok?

Mitja

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

Size is a struct - it comes from System.Drawing namespace. You create a new instance of it. Struct size has its own properties, like Height, Widht ... to which you assign new value like Momerath did).
But I would do it even shorter:

Size s = this.Height + 100;
this.Size = s;
Mitja Bonca 557 Nearly a Posting Maven

I still dont get it what you want to do.
Please explain in some words what is your intention.
Why is an array there, what do you put into it? Is it filled in the runtime (in the code), or does it fill from textBox (or some other control)?
Why is textBox there?
And explain that it will make sence. Ok?
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Hi,
your code looks pretty strange, especially the using(xxx) row, but I dont know what those variables mean, so hard to tell...
Lets make it a bit different:

private void DeletingDataBase()
        {
            using (SqlConnection sqlConn = new SqlConnection("ConnectionString"))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    string sqlQuery = "SELECT, INSERT, UPDATE, DELETE";
                    cmd.Connection = sqlConn;
                    cmd.CommandText = sqlQuery;
                    cmd.Connection.Open();
                    try
                    {                        
                        cmd.ExecuteNonQuery();
                    }
                    catch { /*catch an error in here*/ }
                    finally
                    {
                        cmd.Connection.Close();
                    }
                }
            }
        }

Back to your question. Answer is: No.
When you use a keyword "using" the newly created instance in there, closes it self when leaving the using brackets.
This is the same of every instance created (i.e: SqlConnection, StreamReader ...).
But if some einstance needs an open connection, you have to open it (manully) in the code (i.e: sqlConn.Open();).

using(SqlConnection sqlConn = new SqlConnection("string"))
{
    //open the connect (if needed)!
}//here the connection closes it self!

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Size is a read only property. Use Width and Height directly, Size is just a helper property if you need them as a Size object.

Form1 f = new Form1();
 f.Height = 400;
Mitja Bonca 557 Nearly a Posting Maven

:)
Check this out man:

private void method()
        {
            string allText = "1, 2, 3, 4, 5\n2, 3, 4, 5";
            allText = allText.Replace(",", "");
            string[] lines = allText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

            Dictionary<int, List<int>> dic = new Dictionary<int, List<int>>();

            for (int i = 0; i < lines.Length; i++)
            {
                string[] _Chars = lines[i].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                int counter = 0;
                foreach (string _char in _Chars)
                {
                    int number = Convert.ToInt32(_char);
                    if (dic.ContainsKey(counter))
                        dic[counter].Add(number);
                    else
                    {
                        List<int> list = new List<int>();
                        list.Add(number);
                        dic.Add(counter, list);
                    }
                    counter++;
                }
            }

            //NOW lets show what we got:
            string rows = null;
            foreach (KeyValuePair<int, List<int>> item in dic)
            {
                for (int i = 0; i < item.Value.Count; i++)
                    rows += item.Value[i] + " ";
                rows = rows + Environment.NewLine;
            }
            MessageBox.Show("List of new items:\n\n" + rows);
        }

What can you say? Just tell me if you understand the code?!
I have decided to use a Dictonary with adding keys and values into it.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Yep, dataGridView control will be the best option here.

Mitja Bonca 557 Nearly a Posting Maven

Anytime :)

Mitja Bonca 557 Nearly a Posting Maven

And here is the example (better suitable to you) which using dataTable (dataSet) as dataSoucrce. Take a look how it has to be done. The code automatically removed the item from listBox (becuase it was removed from dataTable and its data bound):

public partial class Form1 : Form
    {
        BindingSource bs;
        DataSet ds;
        public Form1()
        {
            InitializeComponent();
                               
            string[] array = new string[] { "A", "B", "C" };
            ds = new DataSet();
            DataTable table = new DataTable("table1");
            table.Columns.Add(new DataColumn("letters", typeof(string)));
            DataRow dr;
            for (int i = 0; i < array.Length; i++)
            {
                dr = table.NewRow();
                dr["letters"] = array[i];
                table.Rows.Add(dr);
            }
            ds.Tables.Add(table);

            //set datasource:
            bs = new BindingSource();
            bs.DataSource = ds.Tables["table1"];
            listBox1.DataSource = bs;
            listBox1.DisplayMember = "letters";
            listBox1.ValueMember = listBox1.DisplayMember;
            listBox1.SelectedIndex = -1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int rowIndex = listBox1.SelectedIndex;
            ds.Tables["table1"].Rows[rowIndex].Delete();
        }
    }

I hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Look at this code how it should be done:

public partial class Form1 : Form
    {
        List<string> list;
        BindingList<string> bindingList;
        public Form1()
        {
            InitializeComponent();
                               
            string[] array = new string[] { "A", "B", "C" };
            list = new List<string>(array);
            bindingList = new BindingList<string>(list);

            listBox1.DataSource = bindingList;
            listBox1.SelectedIndex = -1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string item = listBox1.SelectedItem.ToString();
            bindingList.Remove(item);
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Your are welcome.
What is tabular view?

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

hmm.. dgv is so huge control and there is really a lot to lear if you want to use it and understand its work.
Here you can start learning: http://www.dotnetperls.com/datagridview-tips

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Get, set accessors are great option, becuase you can set it in some place, and retrive (get) it in another. So, even if you dont need it, you can still have it, and use it.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I have an example code with a bit different approach:

//form1:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string[] array = new string[] { "A", "B", "C" };
            this.comboBox1.Items.AddRange(array);
            this.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
        }

        private void comboBox1_SelectedIndexChanged(object obj, EventArgs e)
        {
            string item = comboBox1.GetItemText(comboBox1.SelectedItem);
            if (item != String.Empty)
            {
                Form2 f2 = new Form2(item);
                f2.StartPosition = FormStartPosition.CenterScreen;
                f2.Show(this);
            }
        }
    }

//form2:
    public partial class Form2 : Form
    {
        string item;
        public Form2(string msg)
        {
            InitializeComponent();
            item = msg;
            
            //example to put the string into some control:
            Label label = new Label();
            label.Location = new Point(20, 20);
            label.Text = msg;
            this.Controls.Add(label);
        }

        protected override void OnShown(EventArgs e)
        {
            MessageBox.Show("Value from form1 is:\n" + item);
        }
    }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Hi, and welcome to programming.
About your question, you have to give us an idea of what would you like to do.
Then we`ll help you out.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I did a mistake, sorry. Take a look ones again into my 1st post.
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
Mitja Bonca 557 Nearly a Posting Maven
if(reader.Value(0) == DbNull.Value)
{
    //code!
}
Mitja Bonca 557 Nearly a Posting Maven

I will show some other way of using Threads and using boolean variable to stop it!

Using thread.Abort() method is not a graceful way of stoping the thread. Not that its not correct (it does what its meant for), but there is a better any more appropriate way, as said, using boolean with Join() method.
Here`s a sample:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Feb22Exercise1
{
    public partial class Form1 : Form
    {
        Thread thread;
        delegate void MyDelegate(string message);
        private volatile bool bShouldStop;

        public Form1()
        {
            InitializeComponent();
            button2.Enabled = false;
        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            if (thread != null)
            {
                thread = null;
                bShouldStop = false;
            }
            thread = new Thread(new ThreadStart(DoWork));
            thread.Start();
            button1.Enabled = false;
            button2.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //thread.Abort();
            RequestStop();
            Thread.Sleep(100);
            thread.Join();
            textBox1.Text = "";
            
            button1.Enabled = true;
            button2.Enabled = false;
        }

        private void DoWork()
        {
            for (int i = 0; i < 1000; i++)
            {
                if (!bShouldStop)
                {
                    UpdateTextBox(i.ToString());
                    Thread.Sleep(100);
                }
                else
                    break;

            }
        }
        public void RequestStop()
        {
            bShouldStop = true;
        }

        private void UpdateTextBox(string msg)
        {
            if (textBox1.InvokeRequired)
                this.textBox1.Invoke(new MyDelegate(UpdateTextBox), new object[] { msg });
            else
            {
                if (thread.IsAlive)
                    this.textBox1.Text = msg;
                else
                    this.textBox1.Text = "";
            }
        }
    }        
}

Mitja

Mitja Bonca 557 Nearly a Posting Maven

I`m afraid not. There is plenty of data to save. You can create a progressBar, which will show the progress of saving, and create a new thread which will do the saving (and restoring data back to richTextBox).
Btw: but even the type varchar should do it. Maybe you didn`t set the lenght long enough?

Mitja Bonca 557 Nearly a Posting Maven

Instead of creating a new class and methods to fill the class we can use LINQ to do that for us:

var allItems = item.Zip(location, (i, l) => new {Item = i, Location = l});

Interesting...
but there is some code missing. Would you mind showing it all? I mean, where from is "item" and "Zip"? Is Zip methodonly in VS2010, cause I dont have it it VS 2008.

Mitja Bonca 557 Nearly a Posting Maven

btw, why do you need a timer in the code?
I did what I thought you want. Tell me if this is it.

int sRight;
        int sLeft;
        public MainForm()
        {
            InitializeComponent();
            this.KeyDown += new KeyEventHandler(MainForm_KeyDown);
        }

        private void MainForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Right)
            {
                if (sRight == 0)
                {
                    sLeft = 0;
                    sRight = 0;
                }
                sRight++;
                timer1.Enabled = true;
                timer1.Interval = (200);

            }
            if (e.KeyCode == Keys.Left)
            {
                if (sLeft == 0)
                {
                    sRight = 0;
                    sLeft = 0;
                }
                sLeft++;
                timer1.Enabled = true;
                timer1.Interval = (200);
            }
        }     

        private void timer1_Tick(object sender, EventArgs e)
        {
            if ((sLeft >= 0 && sLeft <= 30) && (sRight >= 0 && sRight <= 30))
            {
                if (sRight > 0)
                    label1.Text = sRight.ToString();
                else
                    label1.Text = "";
                if (sLeft > 0)
                    label2.Text = sLeft.ToString();
                else
                    label2.Text = "";
                timer1.Enabled = false;
            }
        }

BTW: How wil the left (label2) count up? With pressing left arrow key?

PS: Edited the code... now its better working! tell me what to you think...

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Where do you have subdirectories?

Mitja Bonca 557 Nearly a Posting Maven

Why would you have drives in seperated combo? Wouldn`t be better to have all in treeView?

Mitja Bonca 557 Nearly a Posting Maven

For login ordinary we have userName and password. So for checking if user exist in the database you only chack for these 2 parameters.

So:

SELECT UserName, Password FROM Users WHERE UserName = 'textBoxUserName.Text'

Now you open an sqlDataReader which wil check if the userName exists.
If exists you compare the Password of this user from the database, with the one from textBoxPassword.Text.
If passwords are equal, login is successful
If not password is incorrect.

If even userName does not exist in the dataBase, login data from textBoxes are completely off.
This is how you do the login checking!

Hope it helps.

PS: here is the full code for login:

public static bool LogingInMethod(string userName, string password)
        {
            bool result = false;

            string sqlQuery = "SELECT UserName, Password FROM Users WHERE UserName ='" + userName + "'";
            using (SqlConnection sqlConn = new SqlConnection(p))
            {
                SqlCommand cmd = new SqlCommand(sqlQuery, sqlConn);
                SqlDataReader reader;
                bool bHasRows = false;
                try
                {
                    sqlConn.Open();
                    reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())

                            if (password == reader["Password"].ToString().Trim())
                            {
                                result = true;
                                break;
                            }
                        bHasRows = true;
                    }
                    reader.Close();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    sqlConn.Close();
                }
                finally
                {
                    if (sqlConn.State == ConnectionState.Open)
                    {
                        sqlConn.Close();
                    }
                    cmd = null;
                    reader = null;
                    GC.Collect();
                }

                if (result == true)
                {
                    result = true;
                }

                else if (bHasRows == false)
                {
                    MessageBox.Show("Wrong userName.", "Eror", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    result = false;
                }
                else
                {
                    MessageBox.Show("Wrong password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    result = …