PDA

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



arastoahmadi
چهارشنبه 14 آبان 1399, 16:09 عصر
با سلام

دوستان من تو سی شارپ با رویداد cell painting دیتاگریدمو درست کردم ولی متاسفانه موقع اسکرول کردن دیتا گرید ویوم شکل گرید ویوم به هم میریزه ممنون میشم یه راهنمایی بکنید

private void dataGridView1_CellPainting_1(object sender, DataGridViewCellPaintingEventArgs e)
{
if ((e.RowIndex < -1) || (e.RowIndex >= dataGridView1.RowCount) || (e.ColumnIndex < 0) || (e.ColumnIndex >= dataGridView1.Columns.Count))
{
return;
}
e.Handled = true;
if (e.RowIndex == -1)
{



}
else
{

if ((e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected)
{
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(245, 245, 245)), e.CellBounds);


}

else
{
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(255, 255, 255)), e.CellBounds);
}
var format = new StringFormat(StringFormat.GenericDefault);
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Center;
format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
//format.FormatFlags |= StringFormatFlags.NoClip;
var fontfamily = new FontFamily("Cairo");
var font = new Font(fontfamily, 7);
e.Graphics.DrawString(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(), new Font(new FontFamily("cairo"), 9), Brushes.Black, e.CellBounds.Right - 50, e.CellBounds.Top + 20, format);



e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(231, 231, 231)), e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width, 1);


}

}

152398