Hi all
I want to add row programmatically in grid view after loading data(rows) on it.
for example i loaded three rows in datagridview , now I wanna add row in last of rows and write in it "pay".
but when do this shows following error :
Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.
thanks a lot
the section of method :
string re_select_mablagh_ghest = string.Empty;
string re_serial_kala = string.Empty;
string ret_mablgh_soud_yek_month = string.Empty;
string ret_mablagh_ghest_yek_month = string.Empty;
string re_sele_tedad_tasvie_ghest = string.Empty;
DataTable mab_kal = new DataTable();
mab_kal = ff.select_mablagh_ghest(code_m_buyer.Text.ToString(), comboBox1.Text.ToString(), comboBox2.Text.ToString());
foreach (DataRow ii in mab_kal.Rows)
{
re_select_mablagh_ghest = ii["mablag_ghest"].ToString();
}
DataTable qw = new DataTable();
qw = ff.sele_serial_kal(code_m_buyer.Text.ToString(), re_select_mablagh_ghest, comboBox1.Text.ToString(), comboBox2.Text.ToString());
foreach (DataRow qq in qw.Rows)
{
re_serial_kala = qq["serial_kala"].ToString();
}
string ted_fu_ag = ff.tedad_full_aghsat(code_m_buyer.Text.ToString(), comboBox1.Text.ToString(), re_serial_kala);
DataTable mab_soud_yek_mo = new DataTable();
mab_soud_yek_mo = ff.mablagh_soud_yek_mon(code_m_buyer.Text.ToString(), comboBox1.Text.ToString(), re_serial_kala);
foreach (DataRow cx in mab_soud_yek_mo.Rows)
{
ret_mablgh_soud_yek_month = cx["soud_mounth"].ToString();
}
DataTable mablagh_ghest_yek_mon = new DataTable();
mablagh_ghest_yek_mon = ff.mablagh_ghest_yek_mon(code_m_buyer.Text.ToString(), comboBox1.Text.ToString(), re_serial_kala);
foreach (DataRow qt in mablagh_ghest_yek_mon.Rows)
{
ret_mablagh_ghest_yek_month = qt["mablag_ghest"].ToString();
}
re_sele_tedad_tasvie_ghest = ff.sele_tedad_pay_aghsat(code_m_buyer.Text.ToString(), comboBox1.Text.ToString(), "pay", re_serial_kala);
double re_sum = 0;
if (comboBox2.Text != string.Empty)
{
re_sum = ff.tasvie_befor_moed(Convert.ToDouble(ted_fu_ag), Convert.ToDouble(re_sele_tedad_tasvie_ghest), Convert.ToDouble(ret_mablgh_soud_yek_month), Convert.ToDouble(ret_mablagh_ghest_yek_month));
}
else
{
MessageBox.Show(" please enter your serial : ");
return;
}
DialogResult aa = MessageBox.Show(string.Concat(string.Concat("money : ", re_sum), "\n do you sure "), " ", MessageBoxButtons.OKCancel);
if (aa == DialogResult.OK)
{
DataTable gg = new DataTable();
string re_sum_pay_true = string.Empty;
ff.delete_ghesting_with_status_pay_where(code_m_buyer.Text.ToString(), comboBox2.Text, "don't pay");
re_sum_pay_true = ff.sum_status_pay_that_true(code_m_buyer.Text, "pay", comboBox2.Text);
DataTable dt = new DataTable();
DataSet ds = new DataSet();
dt = ghestingTableAdapter.GetData();
DataRow newRow = dt.NewRow();
newRow["Explain"] = "pay";
dt.Rows.Add(newRow);
dataGridView1.DataSource = dt.DefaultView;
gg=ff.select_ghesting_whith_where_coloumn_pay_and_dont_pay(code_m_buyer.Text,comboBox2.Text);
dataGridView1.DataSource = gg;
}
else
{
return;
}
}