How can I get celltips or tooltips to vary from cell to cell in my DataGrid
One way to do this is to use a ToolTip control and reset the control text as the mouse moves from cell to cell. Below is a derived DataGrid class that implements this idea. The main points are: Have members that track the current hitRow and hitCol where the mouse is. In a MouseMove handler, do a HitTest on the mouse location to see if there is a new hit cell. If so, set the hitRow & hitCol, and hook the tooltip to hold your text according to the cell. In our sample, we just display the string value of the grid cell. Finally, in the MouseMove handler, after setting a new text in the tooltip, set the tooltip active so it can show itself in due time. public class DataGridCellTips : DataGrid { private int hitRow; private int hitCol; private System.Windows.Forms.ToolTip toolTip1; public DataGridCellTips() { hitRow = -1; hitCol = -1; this.toolTip1 = new System.Windows.Forms.ToolTip(); this.toolTip1.InitialDelay = 1000; this.MouseMove += new MouseEventHandler(HandleMouseMove); } private void HandleMouseMove(object sender, MouseEventArgs e) { DataGrid.HitTestInfo hti = this.HitTest(new Point(e.X, e.Y)); if (hti.Type == DataGrid.HitTestType.Cell && (hti.Row != hitRow || hti.Column != hitCol)) { //new hit row hitRow = hti.Row; hitCol = hti.Column; if (this.toolTip1 != null && this.toolTip1.Active) this.toolTip1.Active = false; //turn it off this.toolTip1.SetToolTip(this, this[hitRow, hitCol].ToString()); this.toolTip1.Active = true; //make it active so it can show itself //Console.WriteLine(‘MouseMove ‘+ hitRow.ToString() + ‘ ‘ + hitCol.ToString()); } } }
What control do I use to insert Separator lines between Controls in my Dialog?
Use the Label Control with the BorderStyle set to Fixed3D and height set to 2.
How can I make my DataGrid support a single select mode, and not the default multiselect mode
One way to do this is to derive a DataGrid, override its OnMouseDown and OnMouseMove methods. In the OnMouseDown, handle selecting and unselecting in your code without calling the base class if the click is on the header. In the OnMouseMove, don’t call the baseclass to avoid dragging selections. Below is a code snippet for a sample derived DataGrid. You can download a full project (C#, VB). public class MyDataGrid : DataGrid { private int oldSelectedRow = -1; protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) { //don’t call the base class if left mouse down if(e.Button != MouseButtons.Left) base.OnMouseMove(e); } protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) { //don’t call the base class if in header DataGrid.HitTestInfo hti = this.HitTest(new Point(e.X, e.Y)); if(hti.Type == DataGrid.HitTestType.Cell) { if(oldSelectedRow > -1) this.UnSelect(oldSelectedRow); oldSelectedRow = -1; base.OnMouseDown(e); } else if(hti.Type == DataGrid.HitTestType.RowHeader) { if(oldSelectedRow > -1) this.UnSelect(oldSelectedRow); if((Control.ModifierKeys & Keys.Shift) == 0) base.OnMouseDown(e); else this.CurrentCell = new DataGridCell(hti.Row, hti.Column); this.Select(hti.Row); oldSelectedRow = hti.Row; } } }
How can I have a column of icons in my datagrid
You need to derive a custom column style, override its Paint method and draw the image. In the attached samples, (VB and C#), there are two custom column styles. One style is a stand-alone unbound column that just displays an image. The second custom column style adds the image to the left side of a bound column. In both cases, the actual image that is displayed is from an imagelist passed into the column in its constructor. The index of the image to be drawn on a particular row is determined by a delegate passed into the column style through its constructor.
How do I display a splash screen type form, one with only client area (no border or titlebar)
You can download a working project that uses this code. public void CreateMyBorderlessWindow() { this.FormBorderStyle = FormBorderStyle.None; this.MaximizeBox = false; this.MinimizeBox = false; this.StartPosition = FormStartPosition.CenterScreen; this.ControlBox = false; }