Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a form with two gridview one displays the results from a search .textbox and the other displays a selected row from the first grid view . Then the rows in the second gridview is saved into a database call unpaid checks.

What I have tried:

C#
private void btnadd_Click(object sender, EventArgs e)
{
    for (int i = dataGridView1.RowCount - 1; i <= 0; i++)
    {
        DataGridViewRow row = dataGridView1.Rows[i];
       
        if (Convert.ToBoolean(row.Cells["selectrow"].Value = true))
        {
            Formq pan = new Formq();
            pan.ShowDialog(); 
            string may = Formq.mark1;
           productBindingSource4.AddNew();
            dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[1].Value = dataGridView1.Rows[i].Cells[1].Value.ToString();
            dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[2].Value = dataGridView1.Rows[i].Cells[2].Value.ToString();
            dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[3].Value = dataGridView1.Rows[i].Cells[3].Value.ToString();
            dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[4].Value = dataGridView1.Rows[i].Cells[4].Value.ToString();
            dataGridView2.Rows[dataGridView2.Rows.Count-1].Cells["quantity"].Value = may;
           int qu = Int32.Parse(dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells["quantity"].Value.ToString());
            string pp = dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[3].Value.ToString();
            Double rpp = Double.Parse(pp);
            Decimal rrpp = (decimal)rpp;

            Decimal tp = rrpp * qu;
            dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells["tprice"].Value = tp + ".00";

            Double sum = 0;
            for (int f = 0; f < dataGridView2.Rows.Count; f++)
            {
                sum += double.Parse(dataGridView2.Rows[f].Cells[6].Value.ToString());
            }
            string msun = (sum.ToString());
            libt2.Text = msun;

Then it’s form is closed and a dynamic button is created. When I want to update the data in the unpaidchecks . I use this
C#
private void btn_Click(object sender, EventArgs e)
{
    this.Hide();
    salesitems op = new salesitems();
    op.Show();
    int i = 0;
   Button btn = sender as Button;
   string btntext = btn.Text;
   kk.getunpaid(int.Parse(btn.Text));
   op.dataGridView2.DataSource = kk.getunpaid(int.Parse(btn.Text));
    
    foreach (var  dy in kk.getunpaid(int.Parse(btn.Text)))
    {
        op.dataGridView2.Rows[i].Cells["quantity"].Value = dy.quantity.ToString();
        op.dataGridView2.Rows[i].Cells["Tprice"].Value = dy.tprice.ToString();
        i++;
        op.libtabsno.Text = dy.tabel_sno_.ToString();
        op.libuser.Text = dy.user.ToString();
        op.libtno.Text = dy.tabel_no_.ToString();
        op.libt2.Text = dy.total.ToString()

But the problem is , it doesn’t add a new row.
This code dose not work when the
C#
productBindingSource4.AddNew();

The dynamic button is clicked
I need help
Posted
Updated 17-Nov-20 18:31pm
v2
Comments
Jo_vb.net 17-Nov-20 13:48pm    
Do you want a blank new row ?

And I cannot see a productBindingSource4.EndEdit
Mandema 18-Nov-20 12:15pm    
Yea so basically I use .addnew() to add a new row To the binding source then to the gridview it’s bound to a binding source
Jo_vb.net 18-Nov-20 13:19pm    
Perhaps it would be easier for us if we had the complete code of your both Private Void's

With productBindingSource4.AddNew();
Does only a blank row appear and no data or do you get an error or what else?

I think with BindingSource.AddNew() only import from bound textboxes may work.

1 solution

Without your data and the forms to run with it, there isn't anything we can do.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Mandema 17-Nov-20 14:18pm    
I would appreciate if next time you don’t have any help to offer don’t say anything. Rather than undermining me . The first thing one learn after writing a code is debugging it .
Thank you
OriginalGriff 17-Nov-20 14:43pm    
Then explain what you have done to debug your app: at the moment all you have said is "here's my code: it doesn't work".

That's not showing us anything like debugging, or trying to work out what the problem is - that's just throwing your hands up and saying "fix it for me, I don't know what I'm doing".

So get off your high horse and learn to ask a question properly?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900