/// <summary> /// This is a useful default implementation of SearchText method, intended to be called /// by implementors of IVirtualListDataSource. /// </summary> /// <param name="value"></param> /// <param name="first"></param> /// <param name="last"></param> /// <param name="column"></param> /// <param name="source"></param> /// <returns></returns> static public int DefaultSearchText(string value, int first, int last, OLVColumn column, IVirtualListDataSource source) { if (first <= last) { for (int i = first; i <= last; i++) { string data = column.GetStringValue(source.GetNthObject(i)); if (data.StartsWith(value, StringComparison.CurrentCultureIgnoreCase)) { return(i); } } } else { for (int i = first; i >= last; i--) { string data = column.GetStringValue(source.GetNthObject(i)); if (data.StartsWith(value, StringComparison.CurrentCultureIgnoreCase)) { return(i); } } } return(-1); }
/// <summary> /// /// </summary> /// <param name="text"></param> /// <param name="first"></param> /// <param name="last"></param> /// <param name="column"></param> /// <returns></returns> public override int SearchText(string text, int first, int last, OLVColumn column) { if (first <= last) { for (int i = first; i <= last; i++) { string data = column.GetStringValue(this.listView.GetNthItemInDisplayOrder(i).RowObject); if (data.StartsWith(text, StringComparison.CurrentCultureIgnoreCase)) { return(i); } } } else { for (int i = first; i >= last; i--) { string data = column.GetStringValue(this.listView.GetNthItemInDisplayOrder(i).RowObject); if (data.StartsWith(text, StringComparison.CurrentCultureIgnoreCase)) { return(i); } } } return(-1); }
private void fastObjectListView1_CellToolTipShowing(object sender, ToolTipShowingEventArgs e) { //if (Control.ModifierKeys != Keys.Control) // return; OLVColumn col = e.Column ?? e.ListView.GetColumn(0); if (col.Text != "岁数") { return; } string stringValue = col.GetStringValue(e.Model); if (stringValue.StartsWith("3", StringComparison.InvariantCultureIgnoreCase)) { e.IsBalloon = !ObjectListView.IsVistaOrLater; e.ToolTipControl.SetMaxWidth(400); e.Title = "警告"; e.StandardIcon = ToolTipControl.StandardIcons.InfoLarge; e.BackColor = Color.AliceBlue; e.ForeColor = Color.IndianRed; e.AutoPopDelay = 15000; e.Font = new Font("Tahoma", 12.0f); e.Text = "30+岁是个危险年龄!\r\n\r\n" + "注意锻炼身体,不要挂!"; } else { e.Title = "小标签"; e.Text = String.Format("用户 '{0}', 列 '{1}'\r\n值为: '{2}'", ((Person)e.Model).Name, col.Text, stringValue); } }
public void DrawBusinessCard(Graphics g, Rectangle itemBounds, object rowObject, ObjectListView olv, OLVListItem item) { const int spacing = 8; itemBounds.Inflate(-2, -2); const int rounding = 20; GraphicsPath path = this.GetRoundedRect(itemBounds, rounding); g.FillPath(this.BackBrush, path); g.DrawPath(this.BorderPen, path); g.Clip = new Region(itemBounds); Rectangle photoRect = itemBounds; photoRect.Inflate(-spacing, -spacing); RectangleF textBoxRect = photoRect; textBoxRect.X += (photoRect.Width + spacing); textBoxRect.Width = itemBounds.Right - textBoxRect.X - spacing; textBoxRect.X = itemBounds.Left + spacing; textBoxRect.Width = itemBounds.Right - textBoxRect.X - spacing; StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap); fmt.Trimming = StringTrimming.EllipsisCharacter; fmt.Alignment = StringAlignment.Center; fmt.LineAlignment = StringAlignment.Near; String txt = item.Text; using (Font font = new Font("Tahoma", 11)) { SizeF size = g.MeasureString(txt, font, (int)textBoxRect.Width, fmt); RectangleF r3 = textBoxRect; r3.Height = size.Height; path = this.GetRoundedRect(r3, 15); g.FillPath(this.HeaderBackBrush, path); g.DrawString(txt, font, this.HeaderTextBrush, textBoxRect, fmt); textBoxRect.Y += size.Height + spacing; } using (Font font = new Font("Tahoma", 8)) { SizeF size = g.MeasureString("Wj", font, itemBounds.Width, fmt); textBoxRect.Height = size.Height; fmt.Alignment = StringAlignment.Near; for (int i = 0; i < olv.Columns.Count; i++) { OLVColumn column = olv.GetColumn(i); if (column.IsTileViewColumn) { txt = column.Text + ":" + column.GetStringValue(rowObject); g.DrawString(txt, font, this.TextBrush, textBoxRect, fmt); textBoxRect.Y += size.Height; } } } }
public void TestAspectToStringFormat() { OLVColumn column = new OLVColumn(); column.AspectName = "BirthDate"; column.AspectToStringFormat = "{0:dd-mm-yy}"; Assert.AreEqual(String.Format("{0:dd-mm-yy}", this.person1.BirthDate), column.GetStringValue(this.person1)); }
public void TestAspectToStringConverter() { OLVColumn column = new OLVColumn(); column.AspectName = "BirthDate"; column.AspectToStringConverter = delegate(Object x) { return("AspectToStringConverter called"); }; Assert.AreEqual("AspectToStringConverter called", column.GetStringValue(this.person1)); }
void RenderAllText(Graphics g, System.Drawing.Rectangle r) { if (ListView.Columns.Count == 0) { return; } // title OLVColumn titleColumn = ListView.GetColumn(0); Debug.Assert(titleColumn.IsPrimary()); string titleText = titleColumn.GetStringValue(RowObject); bool wordWrap = r.Height < 20 ? false : titleColumn.CheckWordWrap(); Size titleSize = CalculateTextSize(g, titleText, r.Width, wordWrap); titleSize.Height = Math.Min(titleSize.Height, r.Height); DrawText(g, r, titleText, GetForegroundColor(), titleColumn.CheckWordWrap()); // description if (ListView.Columns.Count > 1) { OLVColumn descColumn = ListView.GetColumn(1); string descText = descColumn.GetStringValue(RowObject); if (!string.IsNullOrEmpty(descText)) { Size descSize = CalculateTextSize(g, descText, r.Width, descColumn.WordWrap); Size oneLineSize = CalculateTextSize(g, "Test", Int32.MaxValue, false); for (int h = descSize.Height; h >= 0; h -= oneLineSize.Height) { if (h > 0 && titleSize.Height + h <= r.Height) { var rect = r; rect.Y += titleSize.Height; rect.Height -= titleSize.Height; DrawText(g, rect, descText, GetDescriptionForegroundColor(), true /*descColumn.WordWrap*/); return; } } // draw in one line with title var rect2 = r; rect2.X += titleSize.Width + 5; rect2.Width -= titleSize.Width + 5; DrawText(g, rect2, descText, GetDescriptionForegroundColor(), false); } } }
public static void AddSimpleValueColumn(this ObjectListView listView, Func <object, ulong> addressGetter, ClrDump dump, Func <object, ClrType> typeGetter) { var col = new OLVColumn("Value", null) { Width = 150 }; col.AspectGetter = o => { ClrType type = typeGetter(o); ulong address = addressGetter(o); object result = dump.Eval( () => { if (type.IsPrimitive || type.IsString) { return(type.GetValue(address)); } return(address); } ); return(result); }; listView.AllColumns.Add(col); var menuItem = new ToolStripMenuItem("Copy Value"); listView.ContextMenuStrip.Items.Add(menuItem); menuItem.Click += (o, e) => { if (listView.SelectedItem == null) { return; } int index = listView.SelectedItem.Index; var modelObject = listView.GetModelObject(index); string val = col.GetStringValue(modelObject); string escapeVal = StringHelpers.Escape(val); if (string.IsNullOrEmpty(escapeVal)) { Clipboard.SetText("null"); } else { Clipboard.SetText(escapeVal); } }; }
/// <summary> /// Create an AutoCompleteCellEditor /// </summary> /// <param name="lv"></param> /// <param name="column"></param> public AutoCompleteCellEditor(ObjectListView lv, OLVColumn column) { this.DropDownStyle = ComboBoxStyle.DropDown; Dictionary<String, bool> alreadySeen = new Dictionary<string, bool>(); for (int i = 0; i < Math.Min(lv.GetItemCount(), 1000); i++) { String str = column.GetStringValue(lv.GetModelObject(i)); if (!alreadySeen.ContainsKey(str)) { this.Items.Add(str); alreadySeen[str] = true; } } this.Sorted = true; this.AutoCompleteSource = AutoCompleteSource.ListItems; this.AutoCompleteMode = AutoCompleteMode.Append; }
//Size GetTileTextSize( Graphics g, Size r ) //{ // int height = 0; // for( int i = 0; i < ListView.Columns.Count; i++ ) // { // OLVColumn column = ListView.GetColumn( i ); // if( column.IsPrimary() || column.IsTileViewColumn ) // { // string txt = column.GetStringValue( RowObject ); // if( string.IsNullOrEmpty( txt ) ) // break; // Size size = CalculateTextSize( g, txt, r.Width, column.CheckWordWrap() ); // size.Height = Math.Min( size.Height, r.Height ); // if( height + size.Height > r.Height ) // break; // height += size.Height + 2; // } // } // return new Size( r.Width, height ); //} Size GetAllTextSize(Graphics g, Size r, out bool ellipsis) { ellipsis = false; int totalHeight = 0; // title OLVColumn titleColumn = ListView.GetColumn(0); Debug.Assert(titleColumn.IsPrimary()); string titleText = titleColumn.GetStringValue(RowObject); bool wordWrap = r.Height < 20 ? false : titleColumn.CheckWordWrap(); Size titleSize = CalculateTextSize(g, titleText, r.Width, wordWrap); titleSize.Height = Math.Min(titleSize.Height, r.Height); totalHeight += titleSize.Height + 2; // description if (ListView.Columns.Count > 1) { OLVColumn descColumn = ListView.GetColumn(1); string descText = descColumn.GetStringValue(RowObject); if (!string.IsNullOrEmpty(descText)) { Size descSize = CalculateTextSize(g, descText, r.Width, true); Size oneLineSize = CalculateTextSize(g, "Test", Int32.MaxValue, false); // we can t use Font.Height for (int h = descSize.Height; h >= 0; h -= oneLineSize.Height) { if (totalHeight + h <= r.Height) { ellipsis = descSize.Height > (h != 0 ? h : oneLineSize.Height); //descColumn.WordWrap = true; return(new Size(r.Width, totalHeight + h)); } } } } return(new Size(r.Width, totalHeight)); }
/// <summary> /// Create an AutoCompleteCellEditor /// </summary> /// <param name="lv"></param> /// <param name="column"></param> public AutoCompleteCellEditor(ObjectListView lv, OLVColumn column) { this.DropDownStyle = ComboBoxStyle.DropDown; Dictionary <String, bool> alreadySeen = new Dictionary <string, bool>(); for (int i = 0; i < Math.Min(lv.GetItemCount(), 1000); i++) { String str = column.GetStringValue(lv.GetModelObject(i)); if (!alreadySeen.ContainsKey(str)) { this.Items.Add(str); alreadySeen[str] = true; } } this.Sorted = true; this.AutoCompleteSource = AutoCompleteSource.ListItems; this.AutoCompleteMode = AutoCompleteMode.Append; }
/// <summary> /// Create an AutoCompleteCellEditor /// </summary> /// <param name="lv"></param> /// <param name="column"></param> public AutoCompleteCellEditor(AdvancedListView lv, OLVColumn column) { DropDownStyle = ComboBoxStyle.DropDown; var alreadySeen = new Dictionary <string, bool>(); for (var i = 0; i < Math.Min(lv.GetItemCount(), 1000); i++) { var str = column.GetStringValue(lv.GetModelObject(i)); if (!alreadySeen.ContainsKey(str)) { Items.Add(str); alreadySeen[str] = true; } } Sorted = true; AutoCompleteSource = AutoCompleteSource.ListItems; AutoCompleteMode = AutoCompleteMode.Append; }
/// <summary> /// This is a useful default implementation of SearchText method, intended to be called /// by implementors of IVirtualListDataSource. /// </summary> /// <param name="value"></param> /// <param name="first"></param> /// <param name="last"></param> /// <param name="column"></param> /// <param name="source"></param> /// <returns></returns> static public int DefaultSearchText(string value, int first, int last, OLVColumn column, IVirtualListDataSource source) { if (first <= last) { for (int i = first; i <= last; i++) { string data = column.GetStringValue(source.GetNthObject(i)); if (data.StartsWith(value, StringComparison.CurrentCultureIgnoreCase)) return i; } } else { for (int i = first; i >= last; i--) { string data = column.GetStringValue(source.GetNthObject(i)); if (data.StartsWith(value, StringComparison.CurrentCultureIgnoreCase)) return i; } } return -1; }
public void DrawBusinessCard(Graphics g, Rectangle itemBounds, object rowObject, ObjectListView olv, OLVListItem item) { const int spacing = 8; // Allow a border around the card itemBounds.Inflate(-2, -2); // Draw card background const int rounding = 20; GraphicsPath path = GetRoundedRect(itemBounds, rounding); g.FillPath(BackBrush, path); g.DrawPath(BorderPen, path); g.Clip = new Region(itemBounds); // Draw the photo Rectangle photoRect = itemBounds; photoRect.Inflate(-spacing, -spacing); photoRect.Width = 80; OLVColumn columnLotID = olv.GetColumn(2); Image photo = getImage(columnLotID.GetStringValue(rowObject)); if (photo.Width > photoRect.Width) { photoRect.Height = (int)(photo.Height * ((float)photoRect.Width / photo.Width)); } else { photoRect.Height = photo.Height; } g.DrawImage(photo, photoRect); // Now draw the text portion RectangleF textBoxRect = photoRect; textBoxRect.X += (photoRect.Width + spacing); textBoxRect.Width = itemBounds.Right - textBoxRect.X - spacing; StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap); fmt.Trimming = StringTrimming.EllipsisCharacter; fmt.Alignment = StringAlignment.Center; fmt.LineAlignment = StringAlignment.Near; //String txt = item.Text; String txt = columnLotID.GetStringValue(rowObject); using (Font font = new Font("Tahoma", 11)) { // Measure the height of the title SizeF size = g.MeasureString(txt, font, (int)textBoxRect.Width, fmt); // Draw the title RectangleF r3 = textBoxRect; r3.Height = size.Height; path = GetRoundedRect(r3, 15); g.FillPath(HeaderBackBrush, path); g.DrawString(txt, font, HeaderTextBrush, textBoxRect, fmt); textBoxRect.Y += size.Height + spacing; } // Draw the other bits of information using (Font font = new Font("Tahoma", 8)) { SizeF size = g.MeasureString("Wj", font, itemBounds.Width, fmt); textBoxRect.Height = size.Height; fmt.Alignment = StringAlignment.Near; for (int i = 3; i < olv.Columns.Count; i++) { OLVColumn column = olv.GetColumn(i); if (column.IsTileViewColumn) { txt = column.AspectName + " : " + column.GetStringValue(rowObject); g.DrawString(txt, font, TextBrush, textBoxRect, fmt); textBoxRect.Y += size.Height; } if (i > BusinessCardOverlay.MaxLineItemCard) { break; // stop display other info for high column count } } } }
private void SetupTooltips() { // Setup some more complex tooltips // This is normally done via the ToolTipShowing event, though // many styling properties can be setup beforehand. // Don't use a normal ToolTip control with an ObjectListView. // A normal ToolTip treats the ListView as being a single control // with a single tooltip for the whole control. ObjectListView // has a built-in tooltip mechanism which is much more powerful. // Make the tooltips look somewhat different // Unfortunately, styling on tooltip controls only works on XP! // Even balloon style doesn't look good on systems after XP. // this.olvComplex.CellToolTip.BackColor = Color.Red; // this.olvComplex.CellToolTip.ForeColor = Color.Green; // this.olvComplex.CellToolTip.IsBalloon = true; // this.olvComplex.HeaderToolTip.BackColor = Color.Blue; // this.olvComplex.HeaderToolTip.ForeColor = Color.Red; // this.olvComplex.HeaderToolTip.IsBalloon = true; this.olvComplex.HeaderToolTipShowing += delegate(object sender, ToolTipShowingEventArgs e) { if (Control.ModifierKeys != Keys.Control) { return; } e.Title = "Information"; e.StandardIcon = ToolTipControl.StandardIcons.Info; e.AutoPopDelay = 10000; e.Text = String.Format("More details about the '{0}' column\r\n\r\nThis only shows when the control key is down.", e.Column.Text); }; this.olvComplex.CellToolTipShowing += delegate(object sender, ToolTipShowingEventArgs e) { // Show a long tooltip over cells when the control key is down if (Control.ModifierKeys != Keys.Control) { return; } OLVColumn col = e.Column ?? e.ListView.GetColumn(0); string stringValue = col.GetStringValue(e.Model); if (stringValue.StartsWith("m", StringComparison.InvariantCultureIgnoreCase)) { e.ToolTipControl.SetMaxWidth(400); e.Title = "WARNING"; e.StandardIcon = ToolTipControl.StandardIcons.InfoLarge; // Changing colour doesn't work in systems other than XP e.BackColor = Color.AliceBlue; e.ForeColor = Color.IndianRed; e.AutoPopDelay = 15000; e.Font = new Font("Tahoma", 12.0f); e.Text = "THIS VALUE BEGINS WITH A DANGEROUS LETTER!\r\n\r\n" + "On no account should members of the public attempt to pronounce this word without " + "the assistance of trained vocalization specialists."; } else { e.Text = String.Format("Tool tip for '{0}', column '{1}'\r\nValue shown: '{2}'", ((Person)e.Model).Name, col.Text, stringValue); } }; }
/// <summary> /// /// </summary> /// <param name="text"></param> /// <param name="first"></param> /// <param name="last"></param> /// <param name="column"></param> /// <returns></returns> public override int SearchText(string text, int first, int last, OLVColumn column) { if (first <= last) { for (int i = first; i <= last; i++) { string data = column.GetStringValue(this.listView.GetNthItemInDisplayOrder(i).RowObject); if (data.StartsWith(text, StringComparison.CurrentCultureIgnoreCase)) return i; } } else { for (int i = first; i >= last; i--) { string data = column.GetStringValue(this.listView.GetNthItemInDisplayOrder(i).RowObject); if (data.StartsWith(text, StringComparison.CurrentCultureIgnoreCase)) return i; } } return -1; }
public void DrawBusinessCard(Graphics g, Rectangle itemBounds, object rowObject, ObjectListView olv, OLVListItem item) { const int spacing = 8; // Allow a border around the card itemBounds.Inflate(-2, -2); // Draw card background const int rounding = 20; GraphicsPath path = this.GetRoundedRect(itemBounds, rounding); g.FillPath(this.BackBrush, path); g.DrawPath(this.BorderPen, path); g.Clip = new Region(itemBounds); // Draw the photo Rectangle photoRect = itemBounds; photoRect.Inflate(-spacing, -spacing); Person person = rowObject as Person; if (person != null) { photoRect.Width = 80; string photoFile = String.Format(@".\Photos\{0}.png", person.Photo); if (File.Exists(photoFile)) { Image photo = Image.FromFile(photoFile); if (photo.Width > photoRect.Width) { photoRect.Height = (int)(photo.Height * ((float)photoRect.Width / photo.Width)); } else { photoRect.Height = photo.Height; } g.DrawImage(photo, photoRect); } else { g.DrawRectangle(Pens.DarkGray, photoRect); } } // Now draw the text portion RectangleF textBoxRect = photoRect; textBoxRect.X += (photoRect.Width + spacing); textBoxRect.Width = itemBounds.Right - textBoxRect.X - spacing; StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap); fmt.Trimming = StringTrimming.EllipsisCharacter; fmt.Alignment = StringAlignment.Center; fmt.LineAlignment = StringAlignment.Near; String txt = item.Text; using (Font font = new Font("Tahoma", 11)) { // Measure the height of the title SizeF size = g.MeasureString(txt, font, (int)textBoxRect.Width, fmt); // Draw the title RectangleF r3 = textBoxRect; r3.Height = size.Height; path = this.GetRoundedRect(r3, 15); g.FillPath(this.HeaderBackBrush, path); g.DrawString(txt, font, this.HeaderTextBrush, textBoxRect, fmt); textBoxRect.Y += size.Height + spacing; } // Draw the other bits of information using (Font font = new Font("Tahoma", 8)) { SizeF size = g.MeasureString("Wj", font, itemBounds.Width, fmt); textBoxRect.Height = size.Height; fmt.Alignment = StringAlignment.Near; for (int i = 0; i < olv.Columns.Count; i++) { OLVColumn column = olv.GetColumn(i); if (column.IsTileViewColumn) { txt = column.GetStringValue(rowObject); g.DrawString(txt, font, this.TextBrush, textBoxRect, fmt); textBoxRect.Y += size.Height; } } } }
/// <summary> /// Configure the given text box to autocomplete unique values /// from the given column. At most 1000 rows will be considered. /// </summary> /// <param name="tb">The textbox to configure</param> /// <param name="column">The column used to calculate values</param> /// <param name="maxRows">Consider only this many rows</param> public void ConfigureAutoComplete(TextBox tb, OLVColumn column, int maxRows) { // Don't consider more rows than we actually have maxRows = Math.Min(this.GetItemCount(), maxRows); // Reset any existing autocomplete tb.AutoCompleteCustomSource.Clear(); // CONSIDER: Should we use ClusteringStrategy here? // Build a list of unique values, to be used as autocomplete on the editor Dictionary<string, bool> alreadySeen = new Dictionary<string, bool>(); List<string> values = new List<string>(); for (int i = 0; i < maxRows; i++) { string valueAsString = column.GetStringValue(this.GetModelObject(i)); if (!String.IsNullOrEmpty(valueAsString) && !alreadySeen.ContainsKey(valueAsString)) { values.Add(valueAsString); alreadySeen[valueAsString] = true; } } tb.AutoCompleteCustomSource.AddRange(values.ToArray()); tb.AutoCompleteSource = AutoCompleteSource.CustomSource; tb.AutoCompleteMode = column.AutoCompleteEditorMode; }
public void DrawBusinessCard(Graphics g, Rectangle itemBounds, object rowObject, ObjectListView olv, OLVListItem item) { try { const int spacing = 8; // Allow a border around the card itemBounds.Inflate(-2, -2); // Draw card background const int rounding = 20; GraphicsPath path = this.GetRoundedRect(itemBounds, rounding); g.FillPath(this.BackBrush, path); g.DrawPath(this.BorderPen, path); g.Clip = new Region(itemBounds); // Draw the photo Rectangle photoRect = itemBounds; photoRect.Inflate(-spacing, -spacing); Movie movie = rowObject as Movie; if (movie != null) { photoRect.Width = 200; if (!File.Exists(movie.ImagePath)) { DownloadImage(movie); } if (IsFileExists(movie.ImagePath)) { try { using (var photo = Image.FromFile(movie.ImagePath)) { if (photo.Width > photoRect.Width) { photoRect.Height = (int)(photo.Height * ((float)photoRect.Width / photo.Width)); } else { photoRect.Height = photo.Height; } g.DrawImage(photo, photoRect); } } catch { g.DrawRectangle(Pens.DarkGray, photoRect); File.Delete(movie.ImagePath); } } else { g.DrawRectangle(Pens.DarkGray, photoRect); } } // Now draw the text portion RectangleF textBoxRect = photoRect; textBoxRect.X += (photoRect.Width + spacing); textBoxRect.Width = itemBounds.Right - textBoxRect.X - spacing; using (StringFormat fmt = new StringFormat()) { fmt.Trimming = StringTrimming.EllipsisCharacter; fmt.Alignment = StringAlignment.Center; fmt.LineAlignment = StringAlignment.Near; String txt = item.Text; using (Font font = new Font("Tahoma", 11)) { // Measure the height of the title SizeF size = g.MeasureString(txt, font, (int)textBoxRect.Width, fmt); // Draw the title RectangleF r3 = textBoxRect; r3.Height = size.Height; path = this.GetRoundedRect(r3, 15); g.FillPath(this.HeaderBackBrush, path); g.DrawString(txt, font, this.HeaderTextBrush, textBoxRect, fmt); textBoxRect.Y += size.Height + spacing; } // Draw the other bits of information using (Font font = new Font("Tahoma", 8)) { for (int i = 0; i < olv.Columns.Count; i++) { OLVColumn column = olv.GetColumn(i); if (column.IsTileViewColumn) { SizeF size = g.MeasureString(column.GetStringValue(movie), font, (int)textBoxRect.Width, fmt); textBoxRect.Height = size.Height; fmt.Alignment = StringAlignment.Near; txt = column.GetStringValue(rowObject); g.DrawString(txt, font, this.TextBrush, textBoxRect, fmt); textBoxRect.Y += size.Height; } } } } } catch (Exception ex) { Debug.WriteLine("This exception: " + ex.Message); } }
/// <summary> /// Find the first row in the given range of rows that prefix matches the string value of the given column. /// </summary> /// <param name="text"></param> /// <param name="first"></param> /// <param name="last"></param> /// <param name="column"></param> /// <returns>The index of the matched row, or -1</returns> protected virtual int FindMatchInRange(string text, int first, int last, OLVColumn column) { if (first <= last) { for (int i = first; i <= last; i++) { string data = column.GetStringValue(this.GetNthItemInDisplayOrder(i).RowObject); if (data.StartsWith(text, StringComparison.CurrentCultureIgnoreCase)) return i; } } else { for (int i = first; i >= last; i--) { string data = column.GetStringValue(this.GetNthItemInDisplayOrder(i).RowObject); if (data.StartsWith(text, StringComparison.CurrentCultureIgnoreCase)) return i; } } return -1; }
public void DrawBusinessCard(Graphics g, Rectangle itemBounds, object rowObject, ObjectListView olv, OLVListItem item) { const int spacing = 8; itemBounds.Inflate(-2, -2); const int rounding = 20; GraphicsPath path = this.GetRoundedRect(itemBounds, rounding); Rectangle backBounds = new Rectangle(itemBounds.Location, itemBounds.Size); backBounds.Offset(0, 5); GraphicsPath pathBack = this.GetRoundedRect(backBounds, rounding); int iExist = 0; if (rowObject is CRSelectFunctionCalculateValue && lstExists != null && lstExists.Count > 0 && lstExists.Contains((rowObject as CRSelectFunctionCalculateValue).CRSelectFunction.CRID)) { iExist = lstExists.Count(p => p == (rowObject as CRSelectFunctionCalculateValue).CRSelectFunction.CRID); } g.FillPath(new SolidBrush(Color.FromArgb(32, 86, 129)), pathBack); using (LinearGradientBrush brush = new LinearGradientBrush(itemBounds, Color.FromArgb(109, 166, 213), Color.FromArgb(48, 114, 175), LinearGradientMode.Vertical)) { g.FillPath(brush, path); } if (BorderPen.Width > 2) { g.DrawPath(this.BorderPen, path); } Rectangle rectClip = new Rectangle(itemBounds.Location, itemBounds.Size); rectClip.Inflate(2, 2); g.Clip = new Region(rectClip); Rectangle photoRect = itemBounds; photoRect.Inflate(-spacing, -spacing); RectangleF textBoxRect = photoRect; textBoxRect.X += (photoRect.Width + spacing); textBoxRect.Width = itemBounds.Right - textBoxRect.X - spacing; textBoxRect.X = itemBounds.Left + spacing; textBoxRect.Width = itemBounds.Right - textBoxRect.X - spacing; StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap); fmt.Trimming = StringTrimming.EllipsisCharacter; fmt.Alignment = StringAlignment.Center; fmt.LineAlignment = StringAlignment.Near; String txt = item.Text; using (Font font = new Font("Tahoma", 10, FontStyle.Bold)) { if (iExist > 0) { RectangleF r5 = new RectangleF(textBoxRect.X + (int)textBoxRect.Width - 6, textBoxRect.Y - 10, 16, 16); path = this.GetRoundedRect(r5, 8); g.FillPath(new SolidBrush(Color.FromArgb(221, 140, 1)), path); g.DrawString(iExist.ToString(), font, this.HeaderTextBrush, r5, fmt); } } using (Font font = new Font("Tahoma", 8, FontStyle.Bold)) { SizeF size = g.MeasureString("Wj", font, itemBounds.Width, fmt); textBoxRect.Height = size.Height; fmt.Alignment = StringAlignment.Near; OLVColumn olvStartAge = null, olvEndAge = null; for (int i = 0; i < olv.Columns.Count; i++) { OLVColumn column = olv.GetColumn(i); if (column.IsTileViewColumn && column.Text.Replace(" ", "").ToLower() == "startage") { olvStartAge = column; } else if (column.IsTileViewColumn && column.Text.Replace(" ", "").ToLower() == "endage") { olvEndAge = column; } } string txtAge = ""; if (olvStartAge != null) { txtAge = olvStartAge.GetStringValue(rowObject); } if (olvEndAge != null) { txtAge = txtAge == "" ? olvEndAge.GetStringValue(rowObject) : txtAge + "-" + olvEndAge.GetStringValue(rowObject); } if (txtAge != "") { g.DrawString(txtAge, font, this.TextBrush, textBoxRect, fmt); textBoxRect.Y += size.Height; } for (int i = 0; i < olv.Columns.Count; i++) { OLVColumn column = olv.GetColumn(i); if (column.IsTileViewColumn && column.Text.Replace(" ", "").ToLower() != "startage" && column.Text.Replace(" ", "").ToLower() != "endage") { txt = column.GetStringValue(rowObject); g.DrawString(txt, font, this.TextBrush, textBoxRect, fmt); textBoxRect.Y += size.Height; } } } }