How can I get the number of rows in my DataGrid

One way you can do this is through the BindingManager.Count property. [C#] int numRows = dataGridDetails.BindingContext[dataGridDetails.DataSource, dataGridDetails.DataMember].Count; [VB.NET] Dim numRows as Integer = i dataGridDetails.BindingContext(dataGridDetails.DataSource, dataGridDetails.DataMember).Count;

How do I dynamically load a control from a DLL

You use System Reflection to dynamically load a control. If the DLL is named ‘SpecControls.DLL’ and the class you want is ‘SpecControls.ColorControl’, then use this code. [C#] // load the assembly System.Reflection.Assembly assembly = Assembly.LoadFrom(‘SpecControls.DLL’); // get the type Type t = assembly.GetType(‘SpecControls.ColorControl’); // create an instance and add it. // Control c = (Control)Activator.CreateInstance(t); parent.Controls.Add(c); [VB.NET] ’ load the assembly Dim assembly1 As System.Reflection.Assembly = Assembly.LoadFrom(‘SpecControls.DLL’) ’ get the type Dim t As Type = assembly1.GetType(‘SpecControls.ColorControl’) ’ create an instance and add it. ’ Dim c As Control = CType(Activator.CreateInstance(t), Control) parent.Controls.Add(c)

How do I get the row or column that has been clicked on?

You can use the DataGrid’s HitTest method, passing it a point in the grid’s client coordinate system, and returning a HitTestInfo object that holds all the row and column information that you want. [C#] // X & Y are in the grid’ coordinates. If they are in screen coordinates, call dataGrid1.PointToClient method System.Drawing.Point pt = new Point(X, Y); DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt); if(hti.Type == DataGrid.HitTestType.Cell) { MessageBox.Show(dataGrid1[hti.Row, hti.Column].ToString()); } else if(hti.Type == DataGrid.HitTestType.ColumnHeader) { MessageBox.Show(((DataView) DataGrid1.DataSource).Table.Columns[hti.Column].ToString()); } [VB.NET] ’ X & Y are in the grid’ coordinates. If they are in screen coordinates, call dataGrid1.PointToClient method Dim pt = New Point(X, Y) Dim hti As DataGrid.HitTestInfo = dataGrid1.HitTest(pt) If hti.Type = DataGrid.HitTestType.Cell Then MessageBox.Show(dataGrid1(hti.Row, hti.Column).ToString()) Else If hti.Type = DataGrid.HitTestType.ColumnHeader Then ’assumes datasource is a dataview MessageBox.Show(CType(DataGrid1.DataSource, DataView).Table.Columns(hti.Column).ToString()) End If End If

How can I select the entire row when the user clicks on a cell in the row

Call the DataGrid.Select method from within its mouseup event. [C#] private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { System.Drawing.Point pt = new Point(e.X, e.Y); DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt); if(hti.Type == DataGrid.HitTestType.Cell) { dataGrid1.CurrentCell = new DataGridCell(hti.Row, hti.Column); dataGrid1.Select(hti.Row); } } [VB/NET] Private Sub dataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dataGrid1.MouseUp Dim pt = New Point(e.X, e.Y) Dim hti As DataGrid.HitTestInfo = dataGrid1.HitTest(pt) If hti.Type = DataGrid.HitTestType.Cell Then dataGrid1.CurrentCell = New DataGridCell(hti.Row, hti.Column) dataGrid1.Select(hti.Row) End If End Sub

How do I programmatically scroll the datagrid to a particular row

The DataGrid has a protected GridVScrolled member that can be used to scroll the grid. To use it, you can derive from DataGrid and add a ScrollToRow method. Here is a code snippet. Public Class MyDataGrid Inherits DataGrid Sub ScrollToRow(ByVal row As Integer) If Not Me.DataSource Is Nothing Then Me.GridVScrolled(Me, New ScrollEventArgs(ScrollEventType.LargeIncrement, row)) End If End Sub End Class This solution uses information provided by Daniel Herling (MS) in the microsoft.public.dotnet.framework.windowsforms.databinding newsgroup.