How can I get a CheckBox column in a DataGrid to react to the first click

When you first click into a checkbox column, the checked state of the cell does not change. One way you can make the checked state change on the first click is to handle the grid’s MouseUp event, and change the check value there. [VB.Net} Private myCheckBoxCol As Integer = 9 ’my checkbox column Private Sub DataGrid2_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles DataGrid2.MouseUp Dim hti As DataGrid.HitTestInfo = Me.dataGrid2.HitTest(e.X, e.Y) Try If hti.Type = DataGrid.HitTestType.Cell AndAlso hti.Column = myCheckBoxCol Then Me.dataGrid2(hti.Row, hti.Column) = Not CBool(Me.dataGrid2(hti.Row, hti.Column)) End If Catch ex As Exception MessageBox.Show(ex.ToString()) End Try End Sub ’dataGrid2_MouseUp [C#] private int myCheckBoxCol = 9; //my checkbox column private void dataGrid2_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { DataGrid.HitTestInfo hti = this.dataGrid2.HitTest(e.X, e.Y); try { if( hti.Type == DataGrid.HitTestType.Cell && hti.Column == myCheckBoxCol) { this.dataGrid2[hti.Row, hti.Column] = ! (bool) this.dataGrid2[hti.Row, hti.Column]; } } catch(Exception ex) { MessageBox.Show(ex.ToString()); } }

How do I prevent a control from receiving focus when it receives a mouseclick

You can set the control’s Enabled property to false. This will prevent clicking but also gives the disabled look. There is a ControlStyles.Selectable flag that determines whether the control can get focus or not. But it does not appear to affect some controls such as TextBox. But you can prevent the TextBox from getting focus by overriding its WndProc method and ignoring the mouse down. public class MyTextBox : TextBox { const int WM_LBUTTONDOWN = 0x0201; protected override void WndProc(ref System.Windows.Forms.Message m) { if(m.Msg == WM_LBUTTONDOWN) return; base.WndProc(ref m); } }

I need to perform certain custom processing whenever an MDI child form is added to/removed from the MDIContainer form. How do I determine this?

MDIContainer forms have an MDIClient child window and it is to this MDIClient window that MDI child forms are parented. The MDIClient’s ControlAdded/ControlRemoved events will be fired whenever a child form is added or removed. You can subscribe to these events and add the required processing code from within the handlers. // From within the MDIContainer form, subscribe to the MDIClient’s ControlAdded/ControlRemoved events foreach(Control ctrl in this.Controls) { if(ctrl.GetType() == typeof(MdiClient)) { ctrl.ControlAdded += new ControlEventHandler(this.MDIClient_ControlAdded); ctrl.ControlRemoved += new ControlEventHandler(this.MDIClient_ControlRemoved); break; } } protected void MDIClient_ControlAdded(object sender, ControlEventArgs e) { Form childform = e.Control as Form; Trace.WriteLine(String.Concat(childform.Text, ‘ – MDI child form was added.’)); } protected void MDIClient_ControlRemoved(object sender, ControlEventArgs e) { Trace.WriteLine(String.Concat(e.Control.Text, ‘ – MDI child form was removed.’)); }

How can I import a CSV file into a DataTable

Here is a solution suggested by Elan Zhou (MS) on the microsoft.public.dotnet.languages.vb newsgroup. You can also use the following code: 1. Put a DataGrid on the form. 2. Try the following sample code: (Suppose the csv is c:\test.csv.) Imports System.Data Imports System.Data.OleDb Public Class Form1 Inherits System.Windows.Forms.Form Dim objDataset1 As DataSet() Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sConnectionString As String = ‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\;Extended Properties=Text;’ Dim objConn As New OleDbConnection(sConnectionString) objConn.Open() Dim objCmdSelect As New OleDbCommand(‘SELECT * FROM test.csv’, objConn) Dim objAdapter1 As New OleDbDataAdapter() objAdapter1.SelectCommand = objCmdSelect Dim objDataset1 As New DataSet() objAdapter1.Fill(objDataset1, ‘Test’) DataGrid1.DataSource = objDataset1.Tables(0).DefaultView objConn.Close() End Sub End Class

GDI+ Programming: Creating Custom Controls using C#

GDI+ Programming: Creating Custom Controls using C# by Eric White, Chris Garrett. Wrox Press Inc; ISBN: 1861006314 The title of the this book is kind of misleading. It is an excellent introduction to GDI+. In addition to GDI+ there is also some information on control designers that will be useful to control authors.