index column negative

  • 209 Views
  • Last Post 20 March 2019
  • Topic Is Solved
Stylus STYLUS posted this 19 March 2019

Need to copy row from one table to another

Some help

    Private void roba_uslugeDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)  
    {  
        DataGridViewRow row = new DataGridViewRow();  

        for (int i = 0; i < roba_uslugeDataGridView.Rows.Count; i++)  
        {  
            row = (DataGridViewRow)roba_uslugeDataGridView.SelectedRows[i].Clone();  
            int intColIndex = 0;  

            foreach (DataGridViewCell cell in roba_uslugeDataGridView.SelectedRows[i].Cells)  
            {  
                var ColIndex = dataGridView1.Rows.Add();  
                dataGridView1.Rows[intColIndex].Cells["redni_broj"].Value = intColIndex + 1;  
                dataGridView1.Rows[intColIndex].Cells["bar_kod"].Value = cell.Value.ToString();  
                dataGridView1.Rows[intColIndex].Cells["sifra"].Value = cell.Value;  
                dataGridView1.Rows[intColIndex].Cells["naziv_artikla"].Value = cell.Value;  
                dataGridView1.Rows[intColIndex].Cells["cijena"].Value = cell.Value;  
                dataGridView1.Rows[intColIndex].Cells["kolicina"].Value = "1";  
                foreach (DataGridViewRow g1 in dataGridView1.Rows)  
                {  
                    g1.Cells["ukupno"].Value = (Convert.ToDouble(g1.Cells["kolicina"].Value) * Convert.ToDouble(g1.Cells["cijena"].Value)).ToString("0.00");  
                }  
                row.Cells[intColIndex].Value = cell.Value;  
                intColIndex++;  
            }  
            dataGridView1.Rows.Add(row);  
        }  
        dataGridView1.AllowUserToAddRows = false;  
        dataGridView1.Refresh();  

    }  
Order By: Standard | Newest | Votes
Stylus STYLUS posted this 20 March 2019

Thank you

jack posted this 20 March 2019

You should copy datasource instead of using foreach loop, then add data to another datagridview.

You can view the video above to know how to do that.

  • Liked by
  • Stylus STYLUS
Close