How do I determine whether a checkbox in my datagrid is checked or not
If the column is a boolean column, you can just cast the object returned by the indexer to a bool and use it. if((bool)dataGridTopics[row, column]) MessageBox.Show(‘I am true’); else MessageBox.Show(‘I am false’);
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
How do I implement an ownerdrawn statusbar so I can put a progressbar in it
Check out the code posted originally in VB by Jacob Grass, and translated to C# by Jason Lavigne on the dotnet.discussion newsgroup at develop.com.
I have code snippets that I use often. How can I manage them so I can easily used them
In Visual Studio, you can store commonly used code snippets on a tab (other than the Clipboard ring) in your Toolbox. You use drag and drop techniques to move the snippets to the Toolbox. To later use a snippet in your code, you drag it from the Toolbox and drop it into your code.
How can I put up a confirmation question when the user tries to delete a row in the datagrid by clicking on the row header and pressing the Delete key
You can handle this by subclassing your grid and overriding either PreProcessMessage or ProcessDialogKey. The code below assumes your datasource is a dataview. If it is not, you could just remove that check [C#] public override bool PreProcessMessage( ref Message msg ) { Keys keyCode = (Keys)(int)msg.WParam & Keys.KeyCode; if(msg.Msg == WM_KEYDOWN && keyCode == Keys.Delete && ((DataView) this.DataSource).AllowDelete) { if(MessageBox.Show(‘Delete this row?’, ”, MessageBoxButtons.YesNo) == DialogResult.No) return true; } return base.PreProcessMessage(ref msg); } [VB.NET] (courtesy of Erik Johansen) Public Class DataGrid_Custom Inherits DataGrid Private Const WM_KEYDOWN = &H100 Public Overrides Function PreProcessMessage(ByRef msg As System.Windows.Forms.Message) As Boolean Dim keyCode As Keys = CType((msg.WParam.ToInt32 And Keys.KeyCode), Keys) If msg.Msg = WM_KEYDOWN And keyCode = Keys.Delete Then If MessageBox.Show(‘Delete This Row?’, ‘Confirm Delete’, MessageBoxButtons.YesNo) = DialogResult.No Then Return True End If End If Return MyBase.PreProcessMessage(msg) End Function End Class