Mitja Bonca 557 Nearly a Posting Maven

This is now working pretty well (just like I understood you). Hope it helps:

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 Feb09Exercise3
{
    public partial class Form1 : Form
    {
        Random random = new Random();
        int allButtons;
        public Form1()
        {
            InitializeComponent();
            foreach (Control c in Controls)
            {
                if (c is Button)
                {
                    c.Click += new EventHandler(c_Click);
                    allButtons++;
                }
            }
            RandomText();        
        }

        private void c_Click(object sender, EventArgs e)
        {
            Button b = sender as Button;
            string strText = b.Text;
            if (strText != String.Empty)
            {
                string items = GetAdjacents(b.Name);
                string[] values = items.Split(',');

                string[] free = null;
                int counter = 0;               
                for (int i = 0; i < values.Length; i++)
                {
                    string name = "button" + values[i];
                    foreach (Control c in Controls)
                    {
                        if (c is Button)
                        {
                            if (c.Name == name && c.Text == String.Empty)
                            {
                                counter++;
                                Array.Resize(ref free, counter);
                                free[counter - 1] = name;
                            }
                        }                        
                    }
                    //FINAL DECISION OF THE NEW RE-LOCATION (using random selection between those places which are free (empty):
                    if ((i + 1) == values.Length)
                    {
                        string item = GetRandomReLocation(free);
                        //var _control = this.Controls.OfType<Button>().Where(c => c.Name == item);
                        (Controls[item] as Button).Text = strText;
                        b.Text = String.Empty;
                    }
                }
            }
        }

        private string GetRandomReLocation(string[] array)
        {
            string item = array[random.Next(0, array.Length)];
            return item;
        }

        private void RandomText()
        {
            Button[] buttons = new Button[] { button1, button2, button3, button4, button5, button6,
                                              button7, button8, button9, button10, button11, button12, 
                                              button13, button14, button15, button16 };
            //insert into 12 buttons (out …
Mitja Bonca 557 Nearly a Posting Maven

Code looks fine to me, including the constructror. The only thing that bothers me, are the names of the nameSpace and the class name - they are both the same. Maybe is this the issue. Not sure, never tried with both same names.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

You would like to get all the values from a dgv`s row?

Lets say you want to get data from 5th row (dgv has 3 columns):

string = column1 = dgv[0,6].Value.ToString();
string = column2 = dgv[1,6].Value.ToString();
string = column3 = dgv[2,6].Value.ToString();

If the column has a default type of string, no need to parse to stirng on the end.
Same goes for columns of type int, boolean, dateTime....
If the column is type of int you simple do:

int column1 = dgv[0,6].Value;//no need to convert

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Becuase you have to check all 4 textBoxes, its better to use only if statement through all three of them:

if (text1.Length == 0)
{
   //message if is empty
}
else
{
    //message if NOT empty!
}

if (text2.Length == 0)
{
    //message if its empty
}
else
{
    //message if NOT empty!
}
if (text2.Length != 0)
{
    //message if its empty
}
else
{
    //message if NOT empty!
}
Mitja Bonca 557 Nearly a Posting Maven

This might help you:

public partial class Form1 : Form
    {
        List<MyObject> list;
        public Form1()
        {
            InitializeComponent();
            CreatingList();
            GetIndex();
        }

        private void CreatingList()
        {
            list = new List<MyObject>();
            MyObject m1 = new MyObject(1, "one");
            MyObject m2 = new MyObject(2, "two");
            list.Add(m1);
            list.Add(m2);
        }

        private void GetIndex()
        {
            int index1 = list.FindIndex(a => a.name == "two");
            int index2 = list.FindIndex(a => a.id == 1);
        }
    }

    class MyObject
    {
        public int id { get; set; }
        public string name { get; set; }

        public MyObject(int _id, string _name)
        {
            id = _id;
            name = _name;
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Yes, it is. If you want to chack one ot ther other state.

Mitja Bonca 557 Nearly a Posting Maven

Yes, I have to do some modification in the code.. the best would be to use a random, to choose or left ot right, or buttom or upper label. I will post a solution.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Try this:

private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.FormBorderStyle = FormBorderStyle.Fixed3D;
            form2.MaximizeBox = false;
            form2.MinimizeBox = false;
            form2.Show(this);
        }
Mitja Bonca 557 Nearly a Posting Maven

On button click event:

private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != String.Empty)
                textBox1.BackColor = Color.Green;
            else
                textBox1.BackColor = Color.Red;
        }
Mitja Bonca 557 Nearly a Posting Maven

You mean the backColor of textBoxes?
If so, depending on which? On emtpy textBox or not empty?

Mitja Bonca 557 Nearly a Posting Maven

Why do you want to use Lock?
To prevent user can resize form?
If so, you use form`s properties like: MaximizeBox, MinimizeBox, like:

//on form1:
Form2 form2 =new Forms();
form2.MaximizeBox = false;
form2.MinimizeBox = false;

Or is there anything else you want to use Lock?

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

I did the code for you. Let me know what you think.
PS: the only problem the code has, is that when is looking for a new empty contol, is looking for an order (from upper left corner, to the down right corner) - I have to use a radnom, to choose the control randomly if there is more then one available to pass the value.

PS: I used buttons instead of labels. Its the same thing, you only chage buttons with labels and will do.
Here is the code:

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 Feb09Exercise3
{
    public partial class Form1 : Form
    {
        Random random = new Random();
        public Form1()
        {
            InitializeComponent();
            foreach (Control c in Controls)
            {
                if (c is Button)
                {
                    c.Click += new EventHandler(c_Click);
                }
            }
            RandomText();
        }

        private void c_Click(object sender, EventArgs e)
        {
            Button b = sender as Button;
            string strText = b.Text;
            if (strText != String.Empty)
            {
                string items = GetAdjacents(b.Name);
                string[] values = items.Split(',');
                bool bGoOut = false;

                for (int i = 0; i < values.Length; i++)
                {
                    if (!bGoOut)
                    {
                        string name = "button" + values[i];
                        foreach (Control c in Controls)
                        {
                            if (c is Button)
                            {
                                if (c.Name == name && c.Text == String.Empty)
                                {
                                    c.Text = strText;
                                    b.Text = String.Empty;
                                    bGoOut = true;
                                    break;
                                }
                            }
                        }
                    }
                    else
                        break;
                }
            }
        }

        private void RandomText()
        {
            Button[] buttons = new Button[] { …
Mitja Bonca 557 Nearly a Posting Maven

Yes, insert null. When inserting into dataBase do:
if parameter is null: DBNull.Value;

Mitja Bonca 557 Nearly a Posting Maven

Sure, anytime.
And thx. I am glad Ican help.
Cya
Mijta

Mitja Bonca 557 Nearly a Posting Maven

Which adjacent label? The closest one on all four sites (up, down ,left and right)? Please defile which one the code needs to check Precisly.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Can you insert 0 (zero) instead of nothing (in case if user does not insert a number)?
I was thinking of using this code then:

string strValue = textBox1.Text.Trim();
            int intValue = 0;
            if (strValue != String.Empty)
                intValue = Convert.ToInt32(strValue);
            else
                intValue = 0;
Mitja Bonca 557 Nearly a Posting Maven

When creating a new button, create a Click event with it:

public void CreateButtons(int NumX, int NumY)
        {
            this.Location = new Point(2, 2);
            this.Size = new Size((NumX + 1) * 40 - 20, (NumY + 1) * 40);

            int temp;
            for (int i = 0; i < NumX; i++)
            {
                for (int j = 0; j < NumY; j++)
                {

                    Buttons[i, j] = new Button();
                    Buttons[i, j].Name = "ItemNum_" + i.ToString();
                    Buttons[i, j].Location = new Point(40 * i, 40 * j);
                    Buttons[i, j].Size = new Size(40, 40);
                    temp = (r.Next(4) + 1);
                    Buttons[i, j].ImageIndex = temp;
                    label5.Text += " " + temp.ToString();
                    ColorTheButtons(Buttons[i, j]);
                    Buttons[i, j].Visible = true;

                    //CREATE A COMMON EVENT:
                    Buttons[i, j].Click += new EventHandler(Form1_Click);

                    this.Controls.Add(Buttons[i, j]);
                    //= Buttons .Controls.Find(Buttons[i,j].Name);

                }
                label5.Text += "\n";
            }
        }

        private void Form1_Click(object sender, EventArgs e)
        {
            Button _button = sender as Button;
            //NOW YOU CAN CONTINUE WITH THE CODE...
            //_button HAS ALL THE PROPERTIES, ANS STUFF OF THE CLICKED BUTTON!  
            //FOR EXAMPLE:
            string name = _button.Text;
        }

And then you will have a common event handler for all the buttons.
Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Simply, ad zach said, from the dropDown menu select Build, and them Publish YourProject.
Then you go Next, select from CD/DVD, select app. will not check for updates (in most cases)and Finish. Thats it. You have a setup.exe, and everyone can install it (this is the simplyest working way).

Mitja Bonca 557 Nearly a Posting Maven

hi, you can try this way:

string a = textBox1.Text;
            string b = textBox2.Text;
            if (a != String.Empty && b != String.Empty)
            { 
                //both ok!
            }
            else if (a == String.Empty)
                MessageBox.Show("Error 1");
            else
                MessageBox.Show("Error 2");
Mitja Bonca 557 Nearly a Posting Maven

No, but this is only to check if the value in textBox is really an integer. If its not, the method will not continue, but will throw an error message.

About your issue, better use Convert method:

int x = Convert.ToInt32(textBoxAddNum1);
//for the y do the same.

Mitja Bonca 557 Nearly a Posting Maven

Since you didnt say much about your issue (I would need some better explanation oif the problem), I will show you how to disable/enable cells.

dgv[columnIndex, rowIndex].ReadOnly = true; //this will disable specific cell!
//set to false, if you want it to be enable again!
//beside, if you want it to make look ore real in gray color, you can change the backColor:
dgv[colummIndex, rowIndex].DefaultCellStyle.BackColor = Color.LightGray;
//and then set it back to white when enabling.

columnIndex is an integer for the column
rowIndex is an integer for the row
like:
dgv[1,3].XXXX:
1. is 2nd column
3. is 4th row

Hopw it helps a bit, if not, I will need some better explanation,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Are you sre those two textBoxes really contains integers ONLY?
Usually you get this kind of error, if the string, which you want to convert to integer, does NOT contains only numbers (with not letters, no dots, or commas).

Do a check if there really isa int:

private void method()
        { 
            int x=0;
            int y=0;
            int result=0;
            string s1 = textBox1.Text.Trim();
            string s2 = textBox2.Text.Trim();
            bool bChecking = int.TryParse(s1, out x);
            if (bChecking)
            {
                bChecking = int.TryParse(s2, out y);
                if (bChecking)
                { 
                //both stirngs are converted to integer successfully!
                    //do the code here!
                }
            }
            if (!bChecking)
                MessageBox.Show("Input are not integers.");
        }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

U can use Thread.Sleep(500); //somehere in the code - 500 is 0.5 secund

Mitja Bonca 557 Nearly a Posting Maven

Would you mind pasting the code in here? Use code block!

Mitja Bonca 557 Nearly a Posting Maven

Of course it will fire. The event is about to fire when ever the value in each cell changes. So that means that it will fire every time something comes into each cell.

You can avoid this by using a flag - a boolean variable, which you will set to true/false. And depending on that it will go through the code of not:

bool bChecking;

        private void YourMethod()
        {
            bChecking = true;
            //for example: here the cellValueChanged will be fired 
            //but it will not execte it becuase the boolan is set to true
            //and when it will come back, you set it back to false (let says default value):
            bChecking = false;

            //and you can do this by selecting true/false where ever you need in the code (on form load when dgv is populating, ...)
        }

        private void datagridview1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (!bChecking)
            {
                MessageBox.Show("Content Has Changed");
            }
        }
ddanbe commented: helpfull +8
Mitja Bonca 557 Nearly a Posting Maven

I would suggest you not to use boolean return type of the method, because it has no point here. You simpy have to pass the appropriate parameters to the insertion method, and do the insertion - using sqlCommand`s executeNonQuery() method. Thats it.

Tak a look at this example:

//calling inset method from your class:
InsertingData(//put parameters in here to pass to the method bellow//);

//insert method:
private void InsertingData(string name, string password, string email)
    {
      string connString = @"server=x;uid=y;pwd=z;database=xyz"; //this is an example, you need your own
      using (SqlConnection sqlConn = new SqlConnection(connString))
      {
        string query = String.Format(@"INSERT INTO Users VALUES (@id, @name, @password, @email)");
        using (SqlCommand cmd = new SqlCommand(query, sqlConn))
        {
          cmd.CommandType = CommandType.Text;
          cmd.Parameters.Add("@id", SqlDbType.Int).Value = 1; //FIND YOUR NEW ID IF YOU HAVE THIS COLUMN IN DATABASE
          cmd.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = name;
          cmd.Parameters.Add("@password", SqlDbType.VarChar, 50).Value = password;
          cmd.Parameters.Add("@email", SqlDbType.VarChar, 50).Value = email;
          cmd.Connection.Open();
          try
          { cmd.ExecuteNonQuery(); }
          catch (Exception ex)
          { 
            MessageBox.Show(ex.Message); 
          }
          finally
          { cmd.Connection.Close(); }
        }
      }
    }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

1. You NEED parameters, if you want to do exactly what you have to do...
but it would be bette to use them in the parametrized query, that means that you add parameters with sql(oleDB) command object, And not insert parameters directly into the query. - So answer in NO - keep the parameters.

Further: take a look into tis example, and do exactly as its is here (you only chaange sqlCommand with OldDbCommand) AND change the query (insert, update tor select) and this is it:

//pass the parameters to this method: 
    private void InsertingData(string name, string password, string email)
    {
      string connString = @"server=x;uid=y;pwd=z;database=xyz"; //this is an example, you need your own
      using (SqlConnection sqlConn = new SqlConnection(connString))
      {
        string query = String.Format(@"INSERT INTO Users VALUES (@id, @name, @password, @email)");
        using (SqlCommand cmd = new SqlCommand(query, sqlConn))
        {
          cmd.CommandType = CommandType.Text;
          cmd.Parameters.Add("@id", SqlDbType.Int).Value = 1; //FIND YOUR NEW ID IF YOU HAVE THIS COLUMN IN DATABASE
          cmd.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = name;
          cmd.Parameters.Add("@password", SqlDbType.VarChar, 50).Value = password;
          cmd.Parameters.Add("@email", SqlDbType.VarChar, 50).Value = email;
          cmd.Connection.Open();
          try
          { cmd.ExecuteNonQuery(); }
          catch (Exception ex)
          { 
            MessageBox.Show(ex.Message); 
          }
          finally
          { cmd.Connection.Close(); }
        }
      }
    }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Your code looks very confused.
From beginning (from the top down):

Your 1st method "Insert_ItemRecords() method is a returned type of boolean, but you return SqlCommand object - this is not good at all.
At the bottom where you call this method, you simply call it , without the return type. If a Method is a boolean return type you should do it like:

void bool InsertMethod(//parameters in here//)
{
   //some code, whihc MUST return true, or false;
    if(something)
        return true;
    else
        return false;
}

//from where you call the upper method:
bool bChecking = InsertMethod(//parameters in here//);
if(bChecking)
{
     MessageBox("Inserting succeeded.");
}
else
     MessageBox("Inserting NOT succeeded.");

OR is your want to do in inserting, you better NOT USE a return type of boolean. But I would not suggest you to use sometihng like this. You better stick to the upper example (of mine).

Hope this helps explaining your issue.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Whole code would look like (as Momerath explained):

dataAdapter.InsertCommand = connection.CreateCommand();
            dataAdapter.InsertCommand.CommandText =
                "insert into Computer (Id, Name) values (@id, @name)";
            dataAdapter.InsertCommand.Parameters.Add("@d", SqlDbType.NVarChar, 16, "Id");
            dataAdapter.InsertCommand.Parameters.Add("@name", SqlDbType.NVarChar, 16, "Name");
Mitja Bonca 557 Nearly a Posting Maven

1st of all, you wrote:
As a global definition

Form newF;

later in code called - which is the first time the form is called
Form newF = new Form();
WRONG!
Why you have again Create a new variable?
Take a look into my exampe, and do:

As a global definition

Form newF;

later in code called - which is the first time the form is called
newF = new Form();

ONE MORE THING: Why is the name of your form "Form"? This is impossible, becase Form is the Reserved word! It can be FormX, but never just a form. If you look on the top of the code edior in the namespace, there is written:

public partial class Form1 : Form //OK!
{
      //Form is a reserved word!!
}

//and you can NOT write this way:
public partial class Form : Form //this is WRONG!
{      
}

-----------------------------------------------------------------------
2nd: It never good to do this kind of coding over forms. This code you can do on the constructor of the "newF", not from main form. For changing the form. you can pass values you need to pass from Main to NewForm. you can do:

//main form:
newF = new Form(lv.Columns[si].Text, coOrds.Count);
newF.Show(this);

//newF:
//constructor
public Form()
{
    InitializeComponent(string item, int value);
    this.Text="Edit or enter text for " + item;
    this.Height = value * 30 + 150;
}

Hope this helps explaining the issue abour …

Mitja Bonca 557 Nearly a Posting Maven

I did two examples for you, one is to use string array the other is to use char (which I prefer most in this case):

private void ReadingFile()
        {
            List<string> list = new List<string>();
            string path = @"C:\1\test11.txt";
            string[] lines = System.IO.File.ReadAllLines(path);

            //1. option:
            for (int i = 0; i < lines.Length; i++)
            {
                string[] line = lines[i].Split(' ');
                for (int j = 0; j < line.Length; j++)
                    list.Add(line[j]);
            }

            //2. option:
            List<string> list2 = new List<string>();
            for (int i = 0; i < lines.Length; i++)
            {
                char[] chars = lines[i].ToCharArray();
                for (int j = 0; j < chars.Length; j++)
                {
                    if (!Char.IsWhiteSpace(chars[j]))
                        list2.Add(chars[j].ToString());
                }
            }
        }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

You have to create a object Form as global variable - so it can be accessed from every place in the class, and there where you want to open it, simple create a new instance of the Form object and open it:

public partial class Form1 : Form
    {
        //This is a global variable:
        Form2 form2;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //create a new instance of the variable:
            form2 = new Form2();
            form2.Show(this);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //same here:
            //create a new instance of the variable:
            form2 = new Form2();
            form2.Show(this);
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

in my line the conifigurationManager is not available in the config list.

You need to add a new Reference (System.Configuration) - right click on References in Solution explorer and choose Add refernece. Go down and select System.Configuration.

Now you write:

private static string connString = ConfigurationManager.ConnectionStrings["YourConnectionStringName"].ConnectionString;

and when you create a connection simply call this value, like

void Method()
{
    using(SqlConnection sqlConn = new SqlConnection(connString))
    {
         //the rest of the code!
         //with using keyWord "using" you dont even need to call Close() method for connection!
    }
}

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

If so, you can do something like this:

private void PopulatingDataTable()
        {
            int max = 5;
            DataTable table = new DataTable("myTable");
            table.Columns.Add(new DataColumn("1stColumn", typeof(int)));
            table.Columns.Add(new DataColumn("2ndColumn", typeof(string)));

            DataRow dr;
            //examples to insert to dt:
            string[] names = new string[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg" };
            for (int i = 0; i < names.Length; i++)
            {
                if (i < max)
                {
                    dr = table.NewRow();
                    dr["1stColumn"] = i + 1;
                    dr["2ndColumn"] = names[i];
                    table.Rows.Add(dr);
                }
                else
                {
                    MessageBox.Show("There is more then 5 items available to insert into table.");
                    break;
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Is there a way to limit the number of records to be inserted into a table using ado.net?

What kind of table are you talking about? DataTable?

Mitja Bonca 557 Nearly a Posting Maven

You are welcome :)
bye,bye
Mitja

Mitja Bonca 557 Nearly a Posting Maven

ADDED:
Or get the width and height of the monitor and set the application to those values (if you want to maximize it).
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Here is another example, this time its a win application.
http://csharp.net-informations.com/communications/csharp-multi-threaded-server-socket.htm
Check the other links bellow to get all the code wanted.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I agree with NewOrder, your code (console`s version) is very poor, and only with that, nothing will work.
For doing this kind of code, you need at least two applications, server and client.
Please take a look at here how it should be done (in a very basic edition): http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=69

Mitja Bonca 557 Nearly a Posting Maven

You said you want to save all items from a listView, not SelectedItem. So why are you using Selecteditem property?

What you hav to do it to loop through all the rows and get the values from all the columns (while in a particualar row), like this:

//...
  string text = null;
  for (int i = 0; i < listView1.Items.Count; i++)
       text += listView1.Items[i].Text + ": " + listView1.Items[i].SubItems[1].Text + Environment.NewLine;    
//...

This should do the trick
Mitja

Mitja Bonca 557 Nearly a Posting Maven

This is might help you out:

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.Diagnostics;  //dont forget to add this namespace!!!

namespace Feb02Exercise
{
    public partial class Form1 : Form
    {
        Timer timer1;
        Stopwatch stopWatch1;
        bool bTimerStopped;
        public Form1()
        {
            InitializeComponent();
            CreatingTimer();
        }

        private void CreatingTimer()
        {
            timer1 = new Timer();
            timer1.Tick+= new EventHandler(timer1_Tick);
            timer1.Interval = 100;

            stopWatch1 = new Stopwatch();
            stopWatch1.Start();
            timer1.Start();
        }

        private void timer1_Tick(object obj, EventArgs e)
        {
            if (stopWatch1.IsRunning)
                ShowingTime();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (stopWatch1.IsRunning)
            {
                if (textBox1.Text != String.Empty)
                {
                    stopWatch1.Stop();
                    bTimerStopped = true;
                    ShowingTime();
                }
                //else, it happens nothing, user must enter some value into textBox
            }
        }

        private void ShowingTime()
        {
            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch1.Elapsed;
            // Format and display the TimeSpan value.
            if (!bTimerStopped)
                labelTime.Text = String.Format("Time elapsed: {0:00}:{1:00} sec", ts.Seconds, ts.Milliseconds);
            else
            {
                labelTime.Text = "You needed " + String.Format("{0:00}:{1:00} sec", ts.Seconds, ts.Milliseconds) + " to press the button.";
                bTimerStopped = false;
            }
        }
    }
}
Mitja Bonca 557 Nearly a Posting Maven

Form6 is only the small windows (for export)? And the back form is form5?

But I still dont understand what are you trying to do here?
I need a better explanation. Sorry.
ps: explin this way that everyone can explain (with a bigger picture).

Mitja Bonca 557 Nearly a Posting Maven

Hi,
What means OPD Visit table? What is its purpose?

About your 2nd question, simply put another foreign key of Referring Doctor into the OPD table. What you have to do, when you will insert one or another? For that one which you want to insert an ID (which has to be higher then 0) simple put an integer, but the other put 0 (zero). This way you will know what kind of doctor it is. If the value is zero, you will know its not this type (but the other).
I hope you know what I mean.

Mitja Bonca 557 Nearly a Posting Maven

YOu still didnt answer on my question. Anyway, I did your homework, and here it is:

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

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

        public void PopultingListBox(List<string> list)
        {
            listBox1.Items.Clear();
            foreach (string item in list)
                listBox1.Items.Add(item);
        }
    }

//form2:
Form1 form1;
        public Form2(Form1 _form1)
        {
            InitializeComponent();
            form1 = _form1;

            listView1.Columns.Add("Column 1", 100, HorizontalAlignment.Left);
            listView1.Columns.Add("Column 2", 100, HorizontalAlignment.Center);
            listView1.View = View.Details;
            listView1.FullRowSelect = true;
            listView1.MultiSelect = true;

            PopulatingListView();
        }

        private void PopulatingListView()
        {
            string[] sArray = new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            string[] iArray = new string[] { "0", "6", "8", "5", "2" };
            for (int i = 0; i < sArray.Length; i++)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = sArray[i];
                lvi.SubItems.Add(iArray[i]);
                listView1.Items.Add(lvi);
            }
        }

        private void buttonToForm1_Click(object sender, EventArgs e)
        {
            List<string> list = new List<string>();
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Selected)
                    list.Add(listView1.Items[i].SubItems[1].Text);
            }

            //PASS DATA TO FORM1`S LISTBOX (FOR TEST):
            form1.PopultingListBox(list);
        }
    }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

You didnt say anything about the listView (as is in your code). And your explanation of the issue is very poor - hard to understand what exactly would you like to do. So lets go imagine...

EDIT (after some hours, when all was thought out well :) ):
you have 2 forms. On form1 you have a listBox. On form2 you have a listView, which has 2 columns. You open Form2, and do th selection in listView (could be multiple), and you want to pass data from column 2 to textBox on form1.
How close was that (but consider I had a hard time thinking what you hve had in mind)?

Mitja Bonca 557 Nearly a Posting Maven

Code shows how to bind the data from a database`s table to dataTable and populate dataGridView with it.
And then how to pass the modified (or not) data from dataGridView back to dataBase`s table.

Mitja Bonca 557 Nearly a Posting Maven

The code gets all the files (only names, if you want to get the paths too, simply remove for loop (its only one) from the code. Files are stored into a generic list.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

thx ddanbe, I will.
You can find it here.

Mitja Bonca 557 Nearly a Posting Maven

This is an example of how to use dgv control which gets the data from dataBase, and after doing some work on dgv, the data gets inserted back to db. You can get the code snipet HERE.

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Save them into DataTable and pass it back to db: http://msdn.microsoft.com/en-us/library/59x02y99.aspx