There are 2 forms

1 form - we are sending the full name and the phone number to the TextBox ; also, by calculating the amount to be paid in one of the Label

2 form - suspended component DatаGridView

Question: how to add data from TextBox(ов) and Label(ов) to DatаGridView ?

If possible, in the following order - Last Name, First Name, Middle Name, Telephone, Amount (order).

 n = Sell.dataGridView1.RowCount; if (comboBox1.SelectedIndex == 0) label14.Text = ysl.dataGridView2.Rows[n].Cells[n].Value; // = sum; sum = label14.Text Sell.table1TableAdapter.Insert(n + 1, textBox4.Text, textBox3.Text, textBox1.Text, textBox2.Text, label14.Text); // textBox.Text); 

Here is a sketch with the addition of a ComboBox to the form (but this is not the case now).

Help by example please.

  • How to assign the value of the cell to a variable, I want to assign to the type int, Writes an error, That the type must be object, Although the cell stores the integer type - DevilScream

1 answer 1

If I understand the problem correctly, then you need to create a public method that can add entries to the dataGridView , and dataGridView instance of the class that contains the dataGridView with the designer to the class in which you enter values, and after confirming the data entry, call this method pass the parameters - the data to add. This way you will transfer the data into the correct form.

At the expense of object . The cell returns an object , but using the .ToString() function you can get a string value, after which you can cast to any type, for example

int.Parse(x[x,y].ToString());

I also advise you to add a table of contents in the dataGridView in properties, or programmatically.

  • Thanks for the help - DevilScream