PDA

View Full Version : سوال: مشکل سطر 0 با دیتا گرید



MehdiElexal
دوشنبه 28 بهمن 1392, 18:15 عصر
با سلام
من یه حلقه دارم که شرط هایی رو چک میکنه اگر برقرار بود مخفی میکنه
و این کار رو هم انجام میده
اما در سطر 0 به مشکل میخوره از i visible=false
چطور این مشکل رو حل کنم و ایراد از کجاست ؟
با تشکر


int[] j = { };
for (int i = 0; i < dataGridView1.RowCount-1; i++)
{
for (int x = i+1; x < dataGridView1.RowCount; x++)
{
if (((dataGridView1.Rows[i].Cells[5].Value.ToString()) == (dataGridView1.Rows[x].Cells[5].Value.ToString())) && (System.Convert.ToInt64(dataGridView1.Rows[i].Cells[4].Value) + System.Convert.ToInt64(dataGridView1.Rows[x].Cells[4].Value)) == 0)
{

dataGridView1.Rows[i].Visible = false;
dataGridView1.Rows[x].Visible = false;

dataGridView1.Rows[i].Cells[5].Value = "0";//Shenase
dataGridView1.Rows[x].Cells[5].Value = "0";
//dataGridView1.Rows[2].Visible = false;
}

}
}


پیغام خطا :
Row associated with the currency manager's position cannot be made invisible.

میفهمم خطا چی میگه ولی چطور حلش کنم ؟
با بقیه سطر ها مشکل ندارم و حذف میشه اما سطر 0 ام دچار مشکل میشه
با تشکر

hamid_hr
دوشنبه 28 بهمن 1392, 19:11 عصر
اول باید سطر جاری رو برابر null قرار بدی
فک کنم اینطوری بود
dgv.currentrow = null