开发者

Datagridview painting and Scroll effect on it

Hey frenz, In my project I merged rows with cell painting. It works fine. but when i use scroll bar it gives random output. i.e. Data on that merged cell goes to header of the datagrid view. so any solution . The code is as follows:

private void Daywisegrid_Paint(object sender, PaintEventArgs e)
{
    for (int k = 0; k < BranchIndex.Count; k++)
    { 
        Font fnt = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point);       
        Rectangle rct1 = new Rectangle((Daywisegrid.GetColumnDisplayRectangle(0, true).X),

        (Daywisegrid.GetColumnDisplayRectangle(0, true).Y),    
        Daywisegrid.GetColumnDisplayRectangle(0, true).Width - 1,    
        (Daywisegrid.GetRowDisplayRectangle((Daywisegrid.Rows.Count - 1), true).Top -  
        Daywisegrid.GetRowDisplayRectangle((Daywisegrid.Rows.Count - 1), true).Height));

        Rectangle rct = Daywisegrid.GetRowDisp开发者_如何学编程layRectangle(Convert.ToInt32(BranchIndex[k]), true);
        rct.Height -= 1;
        SizeF s = e.Graphics.MeasureString("Branch", Daywisegrid.Font);
        float lefts = (rct.Width / 2) - (s.Width / 2);
        float tops = rct.Top+((rct.Height/2)-(s.Height / 2));
        e.Graphics.FillRectangle(Brushes.White, rct);
        e.Graphics.DrawString(BranchName[k].ToString(), fnt, Brushes.Black,0, tops);

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜