public int CompareTo(object obj) { // Get other object CustomObject other = obj as CustomObject; return(Name.CompareTo(other.Name)); }
private void OnDataGridViewSort(object sender, DataGridViewSortCompareEventArgs e) { // Get the actual objects CustomObject obj1 = _bindingSource[e.RowIndex1] as CustomObject; CustomObject obj2 = _bindingSource[e.RowIndex2] as CustomObject; e.SortResult = obj1.Name.CompareTo(obj2.Name); e.Handled = true; }
private void OnPaintCell(object sender, DataGridViewCellPaintingEventArgs e) { DataGridView dgView = sender as DataGridView; if (e.ColumnIndex < 0 || e.RowIndex < 0) { return; } if (dgView.Columns[e.ColumnIndex].Name != "Name") { return; } // Get value at cell CustomObject obj = _baseObjects[e.RowIndex] as CustomObject; Rectangle backgroundRect = e.CellBounds; backgroundRect.Inflate(1, 1); Brush backgroundBrush = new SolidBrush(GetColorFromNumber(obj.Value)); e.Graphics.FillRectangle(backgroundBrush, backgroundRect); backgroundRect.Width = 41; backgroundRect.X += 16; backgroundRect.Y += 6; backgroundRect.Height = 14; backgroundBrush = new SolidBrush(Color.White); e.Graphics.FillRectangle(backgroundBrush, backgroundRect); Rectangle r = e.CellBounds; r.Width -= 18; r.X += 18; e.Graphics.DrawString(obj.Name, this.Font, new SolidBrush(Color.Black), r); e.Handled = true; }