I have little problem , I shared images and code below.
I have two datagridview in my code block. First(left side in form) datagridview's name searchDataGridView. This grid shows data from my database by some filters. Second(right side in form) datagridview's name dataGridView1. This grid shows when I click next button if I select some rows from first grid then this rows will add to dataGridView1. This code block working very well but this that my problem when I click next button and selected rows and added to dataGridView1 then searchDataGridVİew will show new items and selected rows will add to datagridView1, but when I add new items to dataGridView older rows will clear and new selected rows will add but I need that news selected rows must add to under older rows. Thank you for helping.
private void buttonNext_Click(object sender, EventArgs e)
{
Search searchObj = new Search();
DataTable dt = new DataTable();
dt.Columns.Add("Item");
dt.Columns.Add("Company");
dt.Columns.Add("Category");
dt.Columns.Add("Price");
foreach (DataGridViewRow drv in searchDataGridView.Rows)
{
bool chkboxselect = Convert.ToBoolean(drv.Cells["CheckBox"].Value);
if (chkboxselect)
{
dt.Rows.Add(drv.Cells[2].Value, drv.Cells[3].Value, drv.Cells[4].Value, drv.Cells[8].Value);
drv.DefaultCellStyle.BackColor = Color.Gray;
drv.DefaultCellStyle.ForeColor = Color.Aqua;
}
dataGridView1.DataSource = dt;
}
counter +=1;
if (counter == maxIndex)
{
counter =0;
}
try
{
searchCategoryComboBox.SelectedIndex = counter;
}
catch (System.ArgumentOutOfRangeException) // CS0168
{
MessageBox.Show("hata yakalandı");
return;
}
//catch for error outofrange
searchCategoryComboBox.SelectedIndex =counter;
searchObj.Company = searchCompanyComboBox.Text;
searchObj.Category = searchCategoryComboBox.Text;
SearchManager searchMangObj = new SearchManager();
DataTable dt2 = searchMangObj.SearchInfo(searchObj);
searchDataGridView.DataSource = dt2;
textBox1.Text = String.Empty;
}