-2

table.Rows.Add(tb_customer.Text, tb_Item_Name.Text, tb_BatchNo.Text, tb_packing.Text,tb_quantity.Text, tb_discount.Text, tb_Price.Text, tb_total_Price.Text, tb_date.Text); dgv_invoiceRecords.DataSource = table;

1 Answers1

0

According to your title, you would like to insert the textbox value to datatable and use

datagridview to show it.

If you want to do it, please refer to the following code example.

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DataTable table = new DataTable();
        private void button1_Click(object sender, EventArgs e)
        {
            table.Rows.Add(txtName.Text, txtAge.Text, txtID.Text, txtScore.Text);
            dataGridView1.DataSource = table;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Age", typeof(string));
            table.Columns.Add("Id", typeof(string));
            table.Columns.Add("Score", typeof(string));
        }
    }

Result: enter image description here

If the above code can not solve your problem, you can provide the specific exception and a completed code.

Jack J Jun
  • 5,633
  • 1
  • 9
  • 27
  • I was doing in this same manner but the datagridView shows all the table as null,howerver when i checked the table (object of DataTable Class), it contain all data ok. – Muhammad Awais May 08 '20 at 08:37
  • Thanks a lot for considering my issue. Now , after a lot of struggle i just gave up this algorithm and changed my pattern of Algorithm in my project.Now its all ok. – Muhammad Awais May 08 '20 at 08:39
  • I am glad that your problem has been solved, you can give your reply and mark it as an answer. Or if you think my reply is ok, you can mark my reply as an answer. – Jack J Jun May 08 '20 at 08:48