How can I convert a long path to a short path?

There is no direct support in the framework to do this. You have to use the GetShortPathName function using PInvoke. This is how the signature for this function looks like: [DllImport(”kernel32.dll”, SetLastError=true, CharSet=CharSet.Auto)] public static extern int GetShortPathName(string longPath, [MarshalAs(UnmanagedType.LPTStr)]StringBuilder ShortPath, [MarshalAs(UnmanagedType.U4)]int bufferSize); Download C# Sample GetShortPathName.zip Download VB.NET sample GetShortPathName_VB.zip

How can I use a mouse to select cell ranges in my datagrid

The Windows Forms DataGrid does not support the selection of a range of cells other than a group of rows. To select a row, you can click on its row header. But if you want to select a rectangular group of cells, you cannot. To add this support, you can catch the mousedown on a cell, and in mousemove, track whether the mouse is dragged with the button down to other cells. If so, draw a selection rectangle over this group of cells. The attached samples (C#, VB) show how this might be done. The drawing of the selection rectangle is done in an OnPaint override. The samples also try to handle autoscrolling as you hit a grid border so the selection process can continue for cells that are not currently visible. To make the selection rectangle look nicer, the code also hides the current cell when it draws a selection rectangle. The samples have a derived DataGrid that has a public member, SelectedRange, that holds the TopLeft and BottomRight coordinates of the selected range. The derived grid also has a public event, SelectionChanging, that fires prior to the selection changing as you drag your mouse. The event passes both the old selection and the new selection, and allows you to cancel the action if you choose.

Is there any way to get detailed error information for Win32 errors when using Platform Invoke?

Yes, you can use the FormatMessage Win32 API. Sample projects for C# and VB.NET are enclosed. This is how the declaration looks like: [DllImport(”Kernel32.dll”)] public static extern int FormatMessage(int flags, IntPtr source, int messageId, int languageId, StringBuilder buffer, int size, IntPtr arguments ); Called like so: // You can call FormatMessage to get a descriptive error message StringBuilder sbFormatMessage = new StringBuilder(1024); retVal = Interop.FormatMessage(Interop.FORMAT_MESSAGE_FROM_SYSTEM, IntPtr.Zero, Marshal.GetLastWin32Error(), 0, sbFormatMessage, sbFormatMessage.Capacity, IntPtr.Zero); Download C# sample, formatmessage.zip Download VB.NET sample, formatmessage_VB.zip

Can I display the rows in my datagrid in a free-form layout using textboxes on a panel

Here is a VB and C# sample showing how you might do this. The idea is to add textboxes and labels to a panel with whatever layout you want to use. Then use DataBindings.Add calls to bind the textboxes to columns in your grid (actually in your grid’s datasource). Then, since the grid and the textboxes share the same BindingContext, you can move the BindingManagerBase.Position property to scroll through the rows in your grid, and the textboxes will remain in sync. You can hide the grid just to show the textboxes if you do not want the grid to have a presence. Also, any edits in the textboxes will appear in the DataGrid and vice versa.

How can I have a column of bitmaps in a DataGrid

You can derive a custom columnstyle and override its Paint method to draw the image. Here are both C# and VB.Net samples. The Paint override offers three ways to draw the bitmap in the cell; size it to fit the cell bounds, size it proportionally to fit the cell bounds, and draw it with it’s original size (clipping the bitmap to fit in the cell bounds). In the sample, the DataGrid is anchored on all four sides, so as you size the form, the DataGrid sizes as well. The dataGrid1_Resized event is handled to dynamically change the PreferredRowHeight and PreferredColumnWidth so the cells occupy all of the datagrid’s client area. So, as you size the form, the grid cells size also so you can easily see the bitmaps.