How can I get text from a column header in a MouseUp event

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) { 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()); } }

How can I direct debug output to a text file

You need to add a Trace Listener to your code. Below is sample code that adds a TextWriterTraceListener (and don’t forget the Flush before you terminate). For more information on tracing in general, look for the topic ‘Tracing Code in an Application’ in your online .NET documentation. //set up the listener… System.IO.FileStream myTraceLog = new System.IO.FileStream(@’C:\myTraceLog.txt’, System.IO.FileMode.OpenOrCreate); TextWriterTraceListener myListener = new TextWriterTraceListener(myTraceLog); ………. //output to the instance of your listener myListener.WriteLine( ‘This is some good stuff’); ……….. //flush any open output before termination… maybe in an override of your form’s OnClosed myListener.Flush();

How can I determine if a string is a valid date

You can use the static DateTime.Parse or DateTime.ParseExact and catch any exceptions. System.DateTime myDateTime; bool isValid = true; try { myDateTime = System.DateTime.Parse(strMyDateTime); } catch (Exception e) { isValid = false; }