Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try Transfer Checked box data in Another DataGridView show a Problem Without Error
Problem is when i Checked only one row From my first DataGridView then in second DataGridView only generate column but data not show , but when i checked second row from First DataGridView then in second DataGridView only Show Second Selected Data not Both

i try
C#
private void LoanData()
        {
            String connstring = ConfigurationManager.ConnectionStrings["FincorpData"].ConnectionString;
            using (OleDbConnection con = new OleDbConnection(connstring))
            {
                con.Open();
                using (OleDbDataAdapter da = new OleDbDataAdapter("select InstallmentNumber, LoanNumber, InstallmentDate, LoanAmount from installment where LoanNumber = @LoanNumber", con))
                {
                    da.SelectCommand.Parameters.AddWithValue("@LoanNumber", txtLoanNumber.Text);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    dataGridView1.DataSource = dt;
                    dataGridView1.Columns[0].Width = 50;
                    dataGridView1.Columns[0].ReadOnly = true;
                    dataGridView1.Columns[1].Width = 85;
                    dataGridView1.Columns[1].ReadOnly = true;
                    dataGridView1.Columns[2].Width = 110;
                    dataGridView1.Columns[2].ReadOnly = true;
                    dataGridView1.Columns[3].Width = 80;
                    dataGridView1.Columns[3].ReadOnly = true;
                    
                }
            }
            DataGridViewCheckBoxColumn chbox = new DataGridViewCheckBoxColumn();
            chbox.HeaderText = "";
            chbox.Width = 30;
            chbox.Name = "checkBoxColumn";
            dataGridView1.Columns.Insert(0, chbox);

        } 

private void btnFind_Click(object sender, EventArgs e)
        {
            if (IsValidated())
            {
                try
                {
                    
                    LoanData();
                    

                }
                catch (ApplicationException ex)
                {
                    MessageBox.Show("Error:" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }


What I have tried:

This Code For Data Show in Second DataGridView

C#
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("InstallmentNumber");
            dt.Columns.Add("LoanNumber");
            dt.Columns.Add("InstallmentDate");
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                bool isSelected = Convert.ToBoolean(row.Cells["checkBoxColumn"].Value);
                if (isSelected)
                {
                    dt.Rows.Add(row.Cells[1].Value, row.Cells[2].Value, row.Cells[3].Value);
                }
            }
            dataGridView2.DataSource = dt;
        }
Posted
Updated 23-Apr-20 0:51am
v2

Start by finding out exactly what is happening - use the debugger to look at your code while it is running. 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
 
Further to Solution 1 - have a look at this Code Project article to get you started on debugging. It's a little out of date now but all the principles still stand
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

Here are Microsoft's offerings
Tutorial: Debug C# code - Visual Studio | Microsoft Docs[^]
First look at the debugger - Visual Studio | Microsoft Docs[^]

There are of course many others to find on the Intranet
 
Share this answer
 

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