That you dont have any loop around the code which shows the progressBar?
Or maybe you call the method multiple times?
Please double check it.

I know it can be creates like:

TextBox[] tbsArray = new TextBox[2];
tbsArray[0] = textBox1;
tbsArray[1] = textBox2;

TextBox[] tbsArray = new TextBox[] { textBox1, textBox2 };

//or in a loop:
foreach(TextBox tb in new TextBox[] { textBox1, textBox2 })

If there is any other way you would like to have it, let us know.

As Jorge mentions, it seems like you accidentally zoomed out in Chrome. From the Tools menu, click Zoom to 100%. You can also hold down the Ctrl key and scroll the mouse up.

This was partly true, but not the zoom that was doing problems, in new chrome there is an icon beside zoom, just clicked on it, and now its all fine :)
thx god!
And thx for your decent explanation. I hope daniweb returns to its best days :)
best regards

No, zoom has nothing to do with it! Its only this webiste that it has been reduced its size. Its like 1/4 of a whole screen resolution (in 1680x1050)

Hi, since this forum has been modified majorly (this happened approx. 6 months ago) nothing works at it should. There is a lot less people asking question (and answering on them), it seems like you have driven them away with these (not-good changes -personally it was whole much better before that huge webiste update), nor the forum it self does not work like it should.
And a few days ago (including today) the forum size has been shrinked, redused to some small size (like 600x400 pixels). This is refering to Chrome web browser, in Opera seem to be all ok.
What is going on here?

I just want to remind you, if this is keep on happening, people will go from here (leaving), to other forums. Just to keep you awake, I dont think nothing bad with this few statements of mine! I hope I will wake you up moderators and people who are responsable for this (used to be) great forum!


YOu have to be aware of one thing: when you close the form (main form you named it), which has been started from Program class with:

 Application.Run(new Form1());

The application will close.
To avoid this, you have to take care of closing all other form before this one.

Why dont you use a normal TextBox control instead of MaskeTextBox?
In IP case, it would be a better option.

Anyway, if you would like to use MaskeTextBox, and if you wanna remove spaces use Replace method of string class:

            string input = "23 .1 .001.200";
            if (input.Contains(" "))
                input = input.Replace(" ", "");

DO NOT make controls public. This is the worse case possible. This is never a good way of (unsafe) coding.
You have other better options:

  • by creating a method on form1 which can be access from form2 to access control on form2
  • by using events

    but in any case, you will need a reference of form2 (but I know you have it).

You cannot access control which were creates on one (usually on UI) thread, from another thread. You will need to Invoke control.
For more info read here:

FOr example to clear selection do:

listBox1..Invoke(() => listBox1.ClearSelection());

This code:

    Form2 f2 = new Form2();
else if (RadioButton2.Checked)
    // do something else

Use int.Parse() method:

if (int.Parse(row.Cells[3].Value.ToString()) >= -1)
   //do work...

If you bind some data from the dataSource to DGV control, Remove the row from the datasource, not from the DGV. This will reflest in removing row from DGV as well.

Do the loop through the rows of dgv and check if row is selected:

   using(SqlConnection conn = new SqlConnection("connString"))
       foreach (DataGridViewRow dr in dataGridView2.Rows)
           DataGridViewCheckBoxCell check = row.Cells[0] as DataGridViewCheckBoxCell;
           if(check != null && (bool)check.Value) //1st parameter must not be null, 2nd parameter must me true!
               string query = @"UPDATE TableName SET FieldName2 = @param1 WHERE FieldName1 = @param2"; //query
               using(SqlCommand cmd = new SqlCommand(query, conn))
                   cmd.Parameters.Add("@param1", SqlDbType.VarChar, 50).Value = row.Cells["ColumnName2"].Value.ToString(); //set appropriate column name or its index
                   cmd.Parameters.Add("@param2", SqlDbType.Int).Value = int.Parse(row.Cells["ColumnName1"].Value.ToString()); //same here!! - this is some id (unique) column
                       if(conn.State != ConnectionState.Open)
                   catch(Exception ex)
                       break; //go out of the loop when 1st error occurs! - you can remove it

Have you set column names? And I would suggest you to set View to Details, not to List or any other type.

How do you intend to pass the data from DGV to textBox? On a row (cell) click?
Some other way?
If so, do it like:

textBox1.Text = dgv[ColumnIndex, RowIndex].Value.ToString();

if you want to add data to textBox (multiline) use += insted of = only and add "\r\n" before code:

textBox1.Text += dgv[ColumnIndex, RowIndex].Value.ToString() + "\r\n"; //for adding new line for next insert
daniel955 commented: nice +1

can you show us your code? No need to paste it all here, but only the basic one, so we can see whats all about.

I would recommend you to fill DataTable from DGV, but there is still not in-built way to do so.
check this link:

I would suggest you to use events.

Retreive the id from the selected tiem, by using DataRowView class:

DataRowView view = comboBox1.SelectedItem as DataRowView;
int id = int.Parse(view["IdColumnName"].ToString());
//us id variable as a value to insert to db.

how do you add to table1 from dgv2? My guess is that you add 2 more columns, instead of adding data to 1st and 2nd columns only (so bellow the previous data).

Use StreamReader to read line by line (rows), and a comma delimiter to split each line (columns).
Then you can for each row do insert or update into database, since you have all the values of a row.
Hope it helps.

On every step of the way through the method the code must return some value, if it cannot continue from there.
So every if, else if and else must return it.

No code, no question.


//on main form:
void OpenClient()
    Client c = new Client(this);

public void AddText(string text)

//on client class:
class Client
    MainForm mf;
    public Client(MainForm _mf)
    { = _mf;

    public DoWork()
        string text = "";
        //do some work ... and add value to text field;
        //and pass to rtb on main form:

You only need the correct connection string to access to database.
And if SSMS (with database) is located on different pc, then you have to open a 1433 port (potr that is used to access to sql server by defalut) in the firewall.

You cannot remove items while inisde loops, nor for or foreach loop.
You will have to create a new list, where you will put numbers to delete, or indexes of them, and then add the duplicates inside out it. After this is done, you will have to do another loop through this new list and remove numbers from original list.

Do you mean, when you select an item on comboBox1, you ADD this item to comboBox2?
Is fo, use Add() method.


When exactly do you wanna clear it? When you click on it, or double click on it?
PS: Create specific event where you wanna do that exactly.

Or I would use


This will put lines into each line (same as in file).