How can I prevent my user from sizing columns in my datagrid

You can do this by subclassing your grid and overriding OnMouseMove, and not calling the baseclass if the point is on the columnsizing border. [C#] public class MyDataGrid : DataGrid { protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) { DataGrid.HitTestInfo hti = this.HitTest(new Point(e.X, e.Y)); if(hti.Type == DataGrid.HitTestType.ColumnResize) { return; //no baseclass call } base.OnMouseMove(e); } } [VB.NET] Public Class MyDataGrid Inherits DataGrid Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs) Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X,e.Y)) If hti.Type = DataGrid.HitTestType.ColumnResize Then Return ’no baseclass call End If MyBase.OnMouseMove(e) End Sub End Class The above code prevents the sizing cursor from appearing, but as Stephen Muecke pointed out to us, if the user just clicks on the border, he can still size the column. Stephen’s solution to this problem is to add similar code in an override of OnMouseDown. [C#] protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) { DataGrid.HitTestInfo hti = this.HitTest(new Point(e.X, e.Y)); if(hti.Type == DataGrid.HitTestType.ColumnResize) { return; //no baseclass call } base.OnMouseDown(e); } [VB.NET] Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs) Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X,e.Y)) If hti.Type = DataGrid.HitTestType.ColumnResize Then Return ’no baseclass call End If MyBase.OnMouseDown(e) End Sub

How do I set default values for new rows in my datagrid

You use the DataColumn.DefaultValue property to provide default values for new rows. You access this property through the DataTable associated with the DataGrid, [C#] this.dataGrid1.DataSource = this._dataSet.Tables[‘orders’]; …. …. this._dataSet.Tables[‘Orders’].Columns[1].DefaultValue = ‘CustID’; // default value for column 1 this._dataSet.Tables[‘Orders’].Columns[‘OrderDate’].DefaultValue = DateTime.Now; // default value for OrderDate column [VB.NET] Me.dataGrid1.DataSource = Me._dataSet.Tables(‘Orders’) …. …. Me._dataSet.Tables(‘Orders’).Columns(1).DefaultValue = ‘CustID’ ’ default value for column 1 Me._dataSet.Tables(‘Orders’).Columns(‘OrderDate’).DefaultValue = DateTime.Now ’ default value for OrderDate column

How can I restrict the characters that my textbox can accept

You can handle the textbox’s KeyPress event and if the char passed in is not acceptable, mark the events argument as showing the character has been handled. Below is a derived TextBox that only accepts digits (and control characters such as backspace, …). Even though the snippet uses a derived textbox, it is not necessary as you can just add the handler to its parent form. [C#] public class NumbersOnlyTextBox : TextBox { public NumbersOnlyTextBox() { this.KeyPress += new KeyPressEventHandler(HandleKeyPress); } private void HandleKeyPress(object sender, KeyPressEventArgs e) { if(!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar)) e.Handled = true; } } [VB.NET] Public Class NumbersOnlyTextBox Inherits TextBox Public Sub New() AddHandler Me.KeyPress, AddressOf HandleKeyPress End Sub ’New Private Sub HandleKeyPress(sender As Object, e As KeyPressEventArgs) If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) Then e.Handled = True End If End Sub ’HandleKeyPress End Class ’NumbersOnlyTextBox