How do I test for a null value in DataView.RowFilter
You can use the IsNull operator. [C#] //the outer quotes are double quotes and the inner quotes are 2 single quotes //Fax is the column mapping name this.dataView1.RowFilter = ‘IsNull(Fax, ’’) = ’’’; // for a numeric null in custNo (suggested by Bob Gibson) this.dataView1.RowFilter = ‘IsNull(custNo, 0) = 0’; [VB.NET] ’the outer quotes are double quotes and the inner quotes are 2 single quotes ’Fax is the column mapping name Me.dataView1.RowFilter = ‘IsNull(Fax, ’’) = ’’’ ’ for a numeric null in custNo (suggested by Bob Gibson) Me.DataView1.RowFilter = ‘IsNull(custNo, 0) = 0’
How do I retrieve the current row from a DataTable bound to a DataGrid after the grid has been sorted
In an unsorted DataGrid bound to a DataTable, you can get a reference to a row in the DataTable through the DataGrid.CurrentRowIndex. [C#] DataTable dt = (DataTable) this.dataGrid1.DataSource; DataRow dr = dt.Rows[this.dataGrid1.CurrentRowIndex); [VB.NET] Dim dt As DataTable = Me.DataGrid1.DataSource Dim dr as DataRow = dt.Rows(Me.DataGrid1.CurrentRowIndex) But if the grid has been sorted, you can no longer get at the current row in the table through the grid’s CurrentRowIndex. But for both unsorted and sorted grids, you can get at the current row through the BindingContext and the Current property of the BindingManagerBase. [C#] BindingManagerBase bm = this.dataGrid1.BindingContextr[this.dataGrid1.DataSource, this.dataGrid1.DataMember]; DataRow dr = ((DataRowView)bm.Current).Row; [VB.NET] Dim bm As BindingManagerBase = Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember) Dim dr As DataRow = CType(bm.Current, DataRowView).Row
How do I hit a web page from within a button handler in my Windows Forms application
Use the Process class found in the System.Diagnostics namespace. Process proc = new Process(); proc.StartInfo.UseShellExecute = true; proc.StartInfo.FileName = @’http://www.microsoft.com’; proc.Start(); // or just put it all as one statement //System.Diagnostics.Process.Start(@’http://www.microsoft.com’);
My application requires a simple ini file. Is there a easy way to implement this without using any parsing
Yes. This may not be the most efficient way to read from a ini file but it is a pretty good solution that is easy to maintain. You can use a XML file to store your settings. Use a DataSet to read from it. Consider a simple sample file, config.ini. It has three parameters base_path, update_path and output_file. These will map to columns in the settings datatable. view config.ini // add error handling DataSet ds = new DataSet(); ds.ReadXml(‘config.ini’, XmlReadMode.Auto); DataTable table = ds.Tables[‘settings’]; DataRow row = table.Rows[0]; string baseFolder = (string)row[‘base_path’]; string updateFolder = (string)row[‘update_path’]; string outputFileName = (string)row[‘output_file’]; You can of course use XmlReader, XmlDocument etc to create and maintain more complex ini files. But this is a quick way to maintain a simple property set.
How can I find all programs with a GUI (not just arbitrary windows) that are running on my local machine
You could use EnumWindows with p/Invoke, but using the static Process.GetProcesses() found in the System.Diagnostics namespace will avoid the interop overhead. [C#] Using System.Diagnostics; … foreach ( Process p in Process.GetProcesses(System.Environment.MachineName) ) { if( p.MainWindowHandle != IntPtr.Zero) { //this is a GUI app Console.WriteLine( p ); // string s = p.ToString(); } } [VB.NET] Imports System.Diagnostics … Dim p As Process For Each p In Process.GetProcesses(System.Environment.MachineName) If p.MainWindowHandle <> IntPtr.Zero Then ’this is a GUI app Console.WriteLine(p) ’ string s = p.ToString(); End If Next p There is one potential problem on Windows 98. If a process was started with ProcessStartInfo.UseShellExecute set to true, this MainWindowHandle is not available.