Mitja Bonca 557 Nearly a Posting Maven

So you have 2 comboBoxes. 1st is bound to dataSource and 2nd comboBox is populated with some values, regarding on comboBox1 selection.
Which values are these, what is seatNumber variable?
Can you please provide some more code?
thx
mitja

Mitja Bonca 557 Nearly a Posting Maven

I did the example code, and it works fine. I have created two form (form1, and form2). Instead of using dropDownList, I have used ComboBox control - its actually the same, you only change the code so it will suit to your control. Ok here it is:


//form1:

public partial class Form1 : Form
 {
  Form2 form2;

  public Form1()
  {
   InitializeComponent();
   this.StartPosition = FormStartPosition.CenterScreen;
   OpeningForm2();

   this.comboBox1.DataSource = form2.list;
   this.comboBox1.DisplayMember = "name";
   this.comboBox1.ValueMember = this.comboBox1.DisplayMember;
   this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
  }

  private void OpeningForm2()
  {
   form2 = new Form2();
   //location Form2 beside Form1 (on right side):
   int x = Screen.PrimaryScreen.Bounds.Width / 2;
   int y = Screen.PrimaryScreen.Bounds.Height / 2;
   form2.Location = new Point(x, y);
   form2.Show();
  }
 }

//form2:
 public partial class Form2 : Form
 {
  public BindingList<Country> list;

  public Form2()
  {
   InitializeComponent();
   list = new BindingList<Country>();

   this.listBox1.DataSource = list;
   this.listBox1.DisplayMember = "name";
   this.listBox1.ValueMember = this.listBox1.DisplayMember;

   this.textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
  }

  private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  {
   if (e.KeyChar == (char)Keys.Enter)
   {
    string item = this.textBox1.Text.Trim();
    if (item != String.Empty)
    {
     Country c = new Country();
     c.name = item;
     list.Add(c);
     //clearing:
     this.textBox1.Text = "";
     
     
    }
   }
  }
 }

//and additionaly class of Country
 public class Country
 {
  public string name { get; set; }
 }

You can find the whole project HERE.

Code is working like you wanted - when the user inserts some text into textbBox on Form2, the string transfers to generic list <T> which is a binding source of listBox (on form2) and comboBox …

Mitja Bonca 557 Nearly a Posting Maven

2. To loop through all controls, and if textBox is found, do something:

private void button2_Click(object sender, EventArgs e)
        {
            foreach (Control c in Controls)
            {
                if (c is TextBox)
                    c.Text = String.Empty;
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

1. You can create an array of all wanted textBoxes:

private void button1_Click(object sender, EventArgs e)
        {
            TextBox[] tb = new TextBox[] { textBox1, textBox2, textBox3, textBox4, textBox5 };
            for (int i = 0; i < tb.Length; i++)
                tb[i].Text = String.Empty;
        }
Mitja Bonca 557 Nearly a Posting Maven

..., but the selection doesn't change from date picker only! I need an object that I can be able to choose both date and time.

Can you please elaborate this issue a bit precisly?

and this works:

DateTime date = dateTimePicker1.Value;
string strDate = String.Format("{0:MM/dd/yy hh:mm tt}", date);

thx,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Where do you have defined "ShortName" property in the clsItemsNumID class? I dont see it.
Do it this way:

public class clsItemsNumID
    {
        public string LongName { get; set; }
        public string ShortName { get; set; }
        public int ID { get; set; }
        
        public clsItemsNumID(int _id, string _long, string _short)
        {
            this.ID = _id;
            this.LongName = _long;
            this.ShortName = _short;
        }
     }

Now you can set the DisplayMember (LongName) and ValueMember (ones ID, other time ShortName).
It has to work.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Have you checked here? http://msdn.microsoft.com/en-us/library/7a2f3ay4(v=vs.80).aspx

You need to create a boolean (type of volatile) and using it, you can then stop the thread.

NewOrder commented: Thanks. you helped me +0
Mitja Bonca 557 Nearly a Posting Maven

This is the game you want I guess:

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 = null;
            try
            {
                item = array[random.Next(0, array.Length)];                
            }
            catch { MessageBox.Show("Some error occured... simply continue!"); }
            return item;
        }

        private void RandomText()
        {
            Button[] buttons = new Button[] { button1, button2, button3, button4, button5, button6,
                                              button7, button8, button9, button10, button11, button12, 
                                              button13, button14, …
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

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, 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

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

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

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

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

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

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

I have create my table at run time. when new table is create then the data of that table show in datagridview. for that I have use dgv if their is any another control to do this task please tell me.

Depends from where you get data?
If this is from dataBase, the best option for sure is DataTable.
If not, there is plentiy better objects to use, like generic BindingList, or generic List.

Tell me whats your source of data?

Mitja Bonca 557 Nearly a Posting Maven

I did some example code for you, which uses a bindingSource and import, export of data to/from xml.
What you have to do: Put tow buttons (addRow and SaveToXml) and a dataGridView Controls on form, and test this 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 Jan30Exercise2
{
    public partial class Form1 : Form
    {
        BindingList<MyData> list;
        public Form1()
        {
            InitializeComponent();
            CreatingDGV();
            GetDataFromXML();
            CreatingDataTable();
        }

        public void GetDataFromXML()
        {
            DataTable dt = CreatingDataTable();
            dt.ReadXml(@"C:\1\test9.xml");
            foreach (DataRow dr in dt.Rows)
                list.Add(new MyData { Id = Convert.ToInt32(dr[0]), Name = dr[1].ToString() });
        }

        private void CreatingDGV()
        {
            list = new BindingList<MyData>();
            dataGridView1.DataSource = list;
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.CellEndEdit += new DataGridViewCellEventHandler(dataGridView1_CellEndEdit);

            //string[] names = new string[] { "Person 1", "Person 2", "Person 3", "Person 4" };
            //for (int i = 0; i < names.Length; i++)
              //  list.Add(new MyData { Id = (i + 1), Name = names[i] });
        }

        private DataTable CreatingDataTable()
        {
            DataTable dt = new DataTable("Users");
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("userName", typeof(string));
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                dt.Rows.Add(dataGridView1[0, i].Value.ToString(), dataGridView1[1, i].Value.ToString());
            dt.AcceptChanges();
            return dt;
        }

        private void buttonToXml_Click(object sender, EventArgs e)
        {
            DataTable dt = CreatingDataTable();
            dt.WriteXml(@"C:\1\test9.xml");
        }

        internal class MyData
        {
            public int Id { get; set; }
            public string Name { get; set; }
        }

        private void buttonNewRow_Click(object sender, EventArgs e)
        {
            list.Add(new MyData { Id = list.Count + 1, Name = "" });
        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            list[e.RowIndex].Name = dataGridView1[1, …
Mitja Bonca 557 Nearly a Posting Maven

The problem is that you do changes in dgv. So if you want to write all the data from dgv to xml, its best to use DataTable object. Create in on form load, and when you want to save the data into xml, pass data from dgv to dataTable, and from there to xml file:

private void Form1_Load(object sender, EventArgs e)
        {
            DataGridView dataGridView1 = new DataGridView();
            DataTable dt = new DataTable("testtable");
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("name", typeof(string));
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                dt.Rows.Add(dataGridView1[0, i].Value.ToString(), dataGridView1[1, i].Value.ToString()); 
            dt.AcceptChanges();
            this.dataGridView1.DataSource = dt.DefaultView;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataTable dt = ((DataView)this.dataGridView1.DataSource).Table;
            dt.WriteXml(@"C:\test\text.xml");
        }
kardo commented: 1 +0
Mitja Bonca 557 Nearly a Posting Maven

You mean table as DataTable? DataTable cannot be bind to dgv control. You can only populate dgv with using DataRow object, like for instance:

dataGridView1.Columns.Add("col1", "ID");
            dataGridView1.Columns.Add("col2", "NAME");
            string[] array1 = new string[] { "one", "two", "three" };

            table = new DataTable("myTable");
            table.Columns.Add(new DataColumn("id", typeof(int)));
            table.Columns.Add(new DataColumn("name", typeof(string)));
           
            DataRow dr;
            for (int i = 0; i < array1.Length; i++)
            {
                dr = table.NewRow();
                dr["id"] = i.ToString();
                dr["name"] = array1[i];
                table.Rows.Add(dr);
            }

            int row = 0;
            foreach (DataRow dr1 in table.Rows)
            {
                dataGridView1.Rows.Add();
                dataGridView1[0, row].Value = dr1[0].ToString();
                dataGridView1[1, row].Value = dr1[1].ToString();
                row++;
            }

If you want o use Binding property, you have to use some other object, like BindingList. See this example:

private struct Test
        {
            public int ID { get; set; }
            public string Name { get; set; }
        }

        private BindingList<Test> list = new BindingList<Test>();

        public Form1()
        {
            InitializeComponent();
            dataGridView1.DataSource = list;
            string[] array1 = new string[] { "one", "two", "three" };

            for (int i = 0; i < array1.Length; i++)
                list.Add(new Test { ID = i, Name = array1[i] });
        }

Hope this helps explaining the difference which object you can and which you cannot directly bind to some controls. But there is plenty of objects you can use as a binding source (like arrays ([]), lists,...).
Mitja

Mitja Bonca 557 Nearly a Posting Maven

or create it a bitr shorter:

int rowIndex = 0;
            int columnIndex = 0;
            for (int i = 0; i < 4; i++)
            {
                TextBox Text = new TextBox();
                Text.Name = "text+" + i + 1;
                Text.TextChanged += new System.EventHandler(this.TB_TextChanged);
                if (i % 2 == 0 && i > 0)
                    rowIndex++;
                if (i % 2 != 0 && i > 0)
                    columnIndex++;
                else
                    columnIndex = 0;
               this.tableLayoutPanel1.Controls.Add(Text, columnIndex, rowIndex);                
            }
Mitja Bonca 557 Nearly a Posting Maven

What do you mean? A method in Win form to insert userName, password and an email to sql dataBase?
YOu have to pass the data from textBoxes to sql command parameters, end execute the procedure.
Try this code:

private void InsertingData()
        {
            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 = textBox1.Text;
                    cmd.Parameters.Add("@password", SqlDbType.VarChar, 50).Value = textBox2.Text;
                    cmd.Parameters.Add("@email", SqlDbType.VarChar, 50).Value = textBox3.Text;
                    cmd.Connection.Open();
                    try { cmd.ExecuteNonQuery(); }
                    catch (Exception ex)
                    { 
                        MessageBox.Show(ex.Message); 
                    }
                    finally { cmd.Connection.Close(); }
                }
            }
        }
GAME commented: Sweet, It worked... +0
Mitja Bonca 557 Nearly a Posting Maven

You`re welcome.

Mitja Bonca 557 Nearly a Posting Maven

I did a semple code, to see what dataSet and dataTables are all about. To test this method, paste it into a windows application project, and run it.
Put a break point and go through the code line by line (with F11).

private void Method()
        {
            DataSet ds = new DataSet();
            DataTable table1 = new DataTable("table one");
            DataTable table2 = new DataTable("table two");

            //creating columns for the tables:
            table1.Columns.Add(new DataColumn("id", typeof(int)));
            table1.Columns.Add(new DataColumn("someText", typeof(string)));

            table2.Columns.Add(new DataColumn("id2", typeof(int)));
            table2.Columns.Add(new DataColumn("someOtherText", typeof(string)));

            //populating tables, one by one and add them to dataSet:
            //populating table 1:
            DataRow dr;
            for (int i = 1; i < 13; i++)
            {
                dr = table1.NewRow();
                dr["id"] = i;
                dr["someText"] = "text with number " + i.ToString();
                table1.Rows.Add(dr);
            }

            //populating table 2:
            for (int i = 101; i < 113; i++)
            {
                dr = table2.NewRow();
                dr["id2"] = i;
                dr["someOtherText"] = "other text with number " + i.ToString();
                table2.Rows.Add(dr);
            }

            //adding both tables to dataSet:
            ds.Tables.AddRange(new DataTable[] { table1, table2 });
            //you could add them seperately, like:
            //ds.Tables.Add(table1);
            //ds.Tables.Add(table2);

            //Now lets loop through the dataSet and write the results out (int messageBox):
            for (int i = 0; i < ds.Tables.Count; i++)      //LOOP THROUGH TABLES OF DATASET
            {
                string text = null;
                foreach (DataRow dr1 in ds.Tables[i].Rows) //LOOP TRGOUGH THE ROWS OF DATATABLE
                {
                    string a = dr1[0].ToString();
                    string b = dr1[1].ToString();
                    text += a + ". " + b + Environment.NewLine;
                }
                MessageBox.Show("In dataSet is dataTable of index [" + i + "] with values:\n" + text); …
Mr.BunyRabit commented: Went further than just telling me how to do it, but showed me the diffirence between the two +1
Mitja Bonca 557 Nearly a Posting Maven

This is the whole code. The only thing you have to take care of, is to get the string of the tag (tag is the name of the object you want to edit - in out example this would be "susp_front"). Or you will set this variable to a tabContol or on some radioButton - its up to you.
And you have to make sure how many textBoxes and lables would you like to have for eact object. You can do a seperated method which would show the exact amount of textBoxes and labels (if you want it to make all automatic). But this is going into a very details.

PS: one more thing: in the method "PopulatingText" you will see I do an array of textBoxes and lables - these are the controls which I putted on the form in a designer, and I operate with them to populate them with appropriate data. With this kind of code you could choose Object by a radio button (front_susp, end_susp,...) and the code will automatically choose how many textBoxes and lables you need (with the appropriate text in each label).

Hope you like it, here it is:

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.Text.RegularExpressions;
using System.IO;

namespace Jan28FindIn_TextFile
{
    public partial class Form1 : Form
    {
        string tag;
        string path;
        string allText;
        string originalText;
        string modifiedText;

        public Form1()
        {
            InitializeComponent();
        }

        private void buttonGet_Click(object sender, EventArgs …
Mitja Bonca 557 Nearly a Posting Maven

I will do it, but I am considering th best option. Its not simple, but not impossible. Will do it for sure.

Mitja Bonca 557 Nearly a Posting Maven

The code for exporting all the values from the file for any kind is now working well. Dont worry or those errors now.
Now iam considering how to do the import - send data back to file to the correct spot. Do you have any idea?
This is a hard task you know. Will take more then then the other.

Mitja Bonca 557 Nearly a Posting Maven

One question about this row:
restlen=0.142 ;0.1m RL, 3625N load

Do you want to show all in a textBox, or only to sign ";", so only this:0.142
or all the string

Mitja Bonca 557 Nearly a Posting Maven

I did an import of data. This is my example file:
Name1
{
x=1
y=2,4
z=3,6
}
Name2
{
x=4,5
y=2
z=6
}
Name3
{
x=7,4
y=5,4
z=5
}
Name4
{
x=5,2
y=6
z=7,3
}
(

(so that you wont wonder where from I get "Name1" - its only an example).
I even included label (beside textBoxes) to get auto-named, depending on the name which is on the left side of the equalizer ("="). This is the code:

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

        private void buttonGet_Click(object sender, EventArgs e)
        {
            string tag = "Name2";
            string tagEnd = "}";
            string path = Environment.CurrentDirectory + @"\text7.txt";
            string allText = System.IO.File.ReadAllText(path);
            string[] array = allText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int start = (Array.IndexOf(array, tag)) + 2;
            int end = 0;
            for (int i = start; i < allText.Length; i++)
            {
                string item = array[i];
                if (item == tagEnd)
                {
                    end = i;
                    break;
                }
            }

            TextBox[] textBoxes = new TextBox[] { textBox1, textBox2, textBox3, textBox4, textBox5 };
            Label[] labels=new Label[]{label1,label2,label3,label4,label5};

            //empty the labels and textBoxes before filling it:
            for (int c = 0; c < textBoxes.Length; c++)
            {
                textBoxes[c].Text = String.Empty;
                labels[c].Text = String.Empty;
            }

            //populating labels and textBoxes from the appropriate content:
            int counter = 0;
            for (int i = start; i < …
ddanbe commented: Nice effort! +8
Mitja Bonca 557 Nearly a Posting Maven

Why do you have 2 closing brackets:
susp_front
{
y=0
z=1.599
restlen=0.142 ;0.1m RL, 3625N load
minlen=0.005
maxlen=0.16
bumpstop_len=0.04
bumpstop_k=70000
k=86150
}
}

Mitja Bonca 557 Nearly a Posting Maven

Ok, I new I was right :)
Anyway, so there is plenty of "NAMES" with their values.
What we need to do, is like ddanbe said, we need some sort of tokenizer to get thw wanted values - and then they need to go back to the same place from where they were taken.

One question:
The pattern is like you said:
NAME1
{
value1
value2
value3
and so on...
}
NAME2
{
value1
value2
value3
and so on...
}


so, how do I know which name to look for?
Just answer me on these 2 questions, and I`ll try to do the code for you.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

I don`t think I can understand you.
Tell me, what is that you are looking for EXACTLY?
Are this only values of X,Y and Z?

If so, are these the only x,y and z in the ini file?
Please, id you need help, I would expect a better understandable explanation.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

This is the only text you have in the file:
location
{
x=0.35
y=0.56
z=-0.5
}

??

or there is more, and you want to 1st find the text "Location" and th values inside brackets?

Mitja Bonca 557 Nearly a Posting Maven

Only ones of course.
Different would be something like that:

string[] array = GetString();
//method GetString returns an array of strings
//you you go through a foreach loop like it:
foreach(string str in array)
{
   here you can loop through str string!
}
Mitja Bonca 557 Nearly a Posting Maven

dgView.Rows.Add(); //what else?

Mitja Bonca 557 Nearly a Posting Maven

btw, one thing to mention here: Why you dont create a login form before the main one even appears?
You can use DialogResult() method to check if the user has entered the correct login data or not. How to use it, you can take a look on example here: http://support.microsoft.com/kb/816145

And this would be my example:

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 is already running.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                using (Login login = new Login())
                {
                    login.StartPosition = FormStartPosition.CenterScreen;
                    if (login.ShowDialog() == DialogResult.OK)
                    {   
                        //passing logged userName into Form1`s constructor                     
                        Application.Run(new Form1(login.strUserName)); 
                    }
                    //if you will turn down the login 
                    //(for example after 3 wrong logins in Login forms)
                    //the app. will close it self!
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

I see...

Mitja Bonca 557 Nearly a Posting Maven

Take a look into the code I did only for you. Its a code, which allows the user to insert as many numbers and operands as he wants to create a formula.
On the end, when he wants to create an out put, he only inserts the enter after number:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jan22Calculator
{
    class Program
    {
        static void Main(string[] args)
        {
            bool bEnd = false;
            decimal total = 0M;
            decimal number = 0M;
            string strOperand = null;
            string strFormula = null;
            int counter = 1;

            Console.WriteLine("Calculator: Please enter number by number, seperated by operands.");
            Console.WriteLine("To get the result, simply write the equals sing just after number (X=)");
            do
            {
                string word = GetCounter(counter);              

                Console.WriteLine("Please enter the " + word + " number:");
                string strNumber = Console.ReadLine();

                
                if (strNumber.Contains("="))
                {
                    strNumber = strNumber.Remove(strNumber.Length - 1, 1);
                    bEnd = true;
                }
                bool bChecking = CheckingNumber(strNumber);
                if (bChecking)
                {
                    strFormula += strNumber;
                    counter++;
                    number = Convert.ToDecimal(strNumber);
                    total = GetTotal(number, total, strOperand);

                    bChecking = false;
                    while (!bChecking && !bEnd)
                    {
                        Console.WriteLine("Please enter the operand (+, -, /, *):");
                        strOperand = Console.ReadLine();
                        bChecking = CheckingOperand(strOperand);
                        if (bChecking)
                            strFormula += strOperand;
                        else
                            Console.WriteLine("Wrong operand.");
                    }
                }
                else
                    Console.WriteLine("This is not the number.");
            }
            while (!bEnd);

            //on the end it shows the final result:
            strFormula = strFormula + "=";
            Console.WriteLine("{0}{1}", strFormula, total.ToString());
            Console.ReadLine();
        }

        public static string GetCounter(int counter)
        {
            string word = null;
            string[] words = { "1st", "2nd", "3rd" };
            if (counter < 3)
                word …
Mitja Bonca 557 Nearly a Posting Maven

Here is an example of how to use a timer. Important to know: Timer tick is the method which is called when the timer come to zero:

public partial class Form1 : Form
    {
        Timer timer1;
        int counter;

        public Form1()
        {
            InitializeComponent();
            label1.Text = "countier: 0";
            CreatingTimer();
        }

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

        private void timer1_Tick(object sender, EventArgs e)
        {
            counter++;
            timer1.Enabled = true;
            label1.Text = "counter: " + counter.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

I will be sincere: I hate that C# does the code instead of me, this way I cant know what is wrong, if there comes to an error. I always like to do all code possible by my self.
Its good to have that in your self too. This way nothing can surprise you. Agree?

hehe, bye
Mitja

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

Anytime :)
just font forget to mark the thread as asnwered.
thx
bye, bye
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Hey, you need to declare somewhere the shortcut, dont you thing. With only adding an "&" sigb infront of the button text in the designer or in the editor, will simply not do.
Take a look at my example - this is it, this is how suppose to be done.
I hope it helps.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

yee, but you didnt have that line of code in your upper example.
So, glad to hear its working.
Please if you are satisfied with the answer, just mark the thread as answered, so everyone who looking for a similar solution, can get it.
bye, bye
Mitja