ghasem110deh
دوشنبه 14 اردیبهشت 1394, 00:52 صبح
سلام به همه ...
مرج کردن سلولهایی که مقدار مساوی دارن خیلی چیز مهمی نیست ولی چون خیلی دنبالش گشتم ، اینجا هم میزارم ! (عکس ضمیمه)
از یه سایت چینی گرفتم ! مواظب باشین سیستم نپوکه http://ashiyane.org/forums/images/smilies/smile.gif
--------------------------------------------------
اول این متودها رو ایجاد کنین :
bool IsTheSameCellValue(int column, int row)
{
DataGridViewCell cell1 = dataGridView1[column, row];
DataGridViewCell cell2 = dataGridView1[column, row - 1];
if (cell1.Value == null || cell2.Value == null)
{
return false;
}
if (cell1.Value.ToString() == cell2.Value.ToString())
{
return true;
}
else
{
return false;
}
}
private bool IsRepeatedCellValue(int p1, int p2)
{
throw new NotImplementedException();
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.RowIndex == 0)
return;
if (IsTheSameCellValue(e.ColumnIndex, e.RowIndex))
{
e.Value = "";
e.FormattingApplied = true;
}
}
حالا تو رویداد CellPainting این کد رو بنویسید :
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) //
{
e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;
if (e.RowIndex < 1 || e.ColumnIndex < 0)
return;
if (IsTheSameCellValue(e.ColumnIndex, e.RowIndex))
{
e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None;
}
else
{
e.AdvancedBorderStyle.Top = dataGridView1.AdvancedCellBorderStyle.Top;
}
در آخر هم توی لود_فرم :
dataGridView1.AutoGenerateColumns = false;
مرج کردن سلولهایی که مقدار مساوی دارن خیلی چیز مهمی نیست ولی چون خیلی دنبالش گشتم ، اینجا هم میزارم ! (عکس ضمیمه)
از یه سایت چینی گرفتم ! مواظب باشین سیستم نپوکه http://ashiyane.org/forums/images/smilies/smile.gif
--------------------------------------------------
اول این متودها رو ایجاد کنین :
bool IsTheSameCellValue(int column, int row)
{
DataGridViewCell cell1 = dataGridView1[column, row];
DataGridViewCell cell2 = dataGridView1[column, row - 1];
if (cell1.Value == null || cell2.Value == null)
{
return false;
}
if (cell1.Value.ToString() == cell2.Value.ToString())
{
return true;
}
else
{
return false;
}
}
private bool IsRepeatedCellValue(int p1, int p2)
{
throw new NotImplementedException();
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.RowIndex == 0)
return;
if (IsTheSameCellValue(e.ColumnIndex, e.RowIndex))
{
e.Value = "";
e.FormattingApplied = true;
}
}
حالا تو رویداد CellPainting این کد رو بنویسید :
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) //
{
e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;
if (e.RowIndex < 1 || e.ColumnIndex < 0)
return;
if (IsTheSameCellValue(e.ColumnIndex, e.RowIndex))
{
e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None;
}
else
{
e.AdvancedBorderStyle.Top = dataGridView1.AdvancedCellBorderStyle.Top;
}
در آخر هم توی لود_فرم :
dataGridView1.AutoGenerateColumns = false;