I try to draw the dashed line(------------) inside the cell right below to the text which is being showed in the cell. Something similar to Url link which comes very below to the text but dashed line rather fixed line using the interface UIElementDrawFilter. I got following drawback.
1. My last cell is only being painted.
2. Dashed line comes above the bottom line of the cell. I need it into very below to the text.
Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Infragistics.Shared; using Infragistics.Win; using Infragistics.Win.UltraWinGrid.Design; using Infragistics.Win.UltraWinGrid; using System.Drawing.Drawing2D; namespace WindowsApplication9 { public partial class Form1 : Form, Infragistics.Win.IUIElementDrawFilter { private string drawlineafter = string.Empty; private DashStyle dashstyle = DashStyle.Dash; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); DataRow myNewRow, myNewRow1, myNewRow2; dt.Columns.Add(new DataColumn("customerId")); dt.Columns.Add(new DataColumn("username")); myNewRow = dt.NewRow(); myNewRow["customerId"] = 1; myNewRow["username"] = "johndoe"; dt.Rows.Add(myNewRow); myNewRow1 = dt.NewRow(); myNewRow1["customerId"] = 2; myNewRow1["username"] = "Uthay"; dt.Rows.Add(myNewRow1); myNewRow2 = dt.NewRow(); myNewRow2["customerId"] = 3; myNewRow2["username"] = "Steve"; dt.Rows.Add(myNewRow2); ultraGrid1.DataSource = dt; this.ultraGrid1.DrawFilter = this; } #region IUIElementDrawFilter Members public bool DrawElement(Infragistics.Win.DrawPhase drawPhase, ref Infragistics.Win.UIElementDrawParams drawParams) { TextUIElement textval = (TextUIElement)drawParams.Element; if (string.IsNullOrEmpty(textval.Text)) return false; if ((textval == null) || (textval.Parent == null)) return false; Rectangle rect = drawParams.Element.Rect; Point pt1 = Point.Empty; Point pt2 = Point.Empty; pt1.Y = rect.Top + (rect.Height); pt1.X = rect.Left + (rect.Width) - 1; pt2.X = rect.Right - (rect.Width) + 1; pt2.Y = pt1.Y; using (Pen pen = new Pen(drawParams.TextBrush)) { Point pt = Point.Empty; pt.X = rect.X; pt.Y = rect.Y; pen.DashStyle = this.dashstyle; drawParams.Graphics.DrawLine(pen, pt1, pt2); drawParams.Graphics.DrawString(textval.Text.ToString(), drawParams.Font, drawParams.TextBrush, pt); } return true; } public Infragistics.Win.DrawPhase GetPhasesToFilter(ref Infragistics.Win.UIElementDrawParams drawParams) { return drawParams.Element is Infragistics.Win.TextUIElement ? Infragistics.Win.DrawPhase.BeforeDrawElement : Infragistics.Win.DrawPhase.None; } #endregion private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e) { } } }
How to achieve things? Some one help me on this please.
Hi,
The DrawFilter you have here is handle BeforeDrawElement and returning true from it for every TextUIElement in the grid. This means that you are telling the grid not to draw any text and that you will draw all of the text yourself. If you just want to draw a line under the text, then this is probably a bad idea.
It would be better to use the AfterDrawForeground phase, which occurs after the text has already been drawn, and then you can draw your line under the text that is already there. Of course, it might be tough to determine the exactly location of the text, but you would have that problem, anyway.
There are a number of problems with this DrawFilter in addition to the phase.
For one thing, it looks like you are drawing the line over the cell's bottom border. This won't work for several reasons. First, since you are using BeforeDrawElement, the line you draw is getting covered by the line the cell is drawing. Second, a cell only draws 1 or 2 of it's own borders, because if it drew all 4, you would end up with double-thick borders between each cell. So the cells in the grid actualy overlap and your line is covered by the next cell.
Another thing is, you are just trapping for a TextUIElement, so your lines will be drawn over not just the cells, but also the column headers, groups headers, summaries, and anything else in the grid that happens to show text. So you will probably want to limit which TextUIElements you are doing this to based on their parent elements.
Anyway... I thought your question was about drawing a line under the text within the cell. So I'm a little puzzled why your code is drawing right on the border between cells. Are you just trying to change the border style of the cells? If so, there's a BorderStyleCell and BorderStyleRow property on the Override.