How can I get rid of the error icon that appears when there is an editing error
Adam Chester gives this solution in a posting on the microsoft.public.dotnet.framework.windowsforms newgroup. DataTable dt = (DataTable)dataGrid1.DataSource; foreach(DataRow row in dt.GetErrors()) { row.RowError = ”; foreach(DataColumn col in dt.Columns) row.SetColumnError(col, ”); }
How do I draw an image with a gray scale?
Here is some code: // Not the closest grayscale representation in the RGB space, but // pretty close. // Closest would be the cubic root of the product of the RGB colors, // but that cannot be represented in a ColorMatrix. public void DrawGrayedImage(Graphics g, Image image, int left, int top) { ImageAttributes ia = new ImageAttributes(); ColorMatrix cm = new ColorMatrix(); // 1/3 on the top 3 rows and 3 columns cm.Matrix00 = 1/3f; cm.Matrix01 = 1/3f; cm.Matrix02 = 1/3f; cm.Matrix10 = 1/3f; cm.Matrix11 = 1/3f; cm.Matrix12 = 1/3f; cm.Matrix20 = 1/3f; cm.Matrix21 = 1/3f; cm.Matrix22 = 1/3f; ia.SetColorMatrix(cm); g.DrawImage(image, new Rectangle(left, top, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, ia); }
Why am I not receiving MouseLeave messages in a Control in my Form?
This usually happens when a Control doesn’t know that the mouse has left its bounds following a mouse enter. This results in the Control not throwing a MouseLeave event for subsequent mouse moves over it. This is possible if you performed some operation when the mouse was within a Control that made it lose its mouse capture, for example, opening a top-level window over the Control such that the mouse is now over this new window. To work around this problem send a WM_MOUSELEAVE manually to the original Control before the offending operation. class NativeMethods { [DllImport(‘user32.dll’, CharSet=CharSet.Auto)] extern public static IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) ; } // Send a WM_MOUSELEAVE manually to a window. NativeMethods.SendMessage(control.Handle, NativeMethods.WM_MOUSELEAVE, IntPtr.Zero, IntPtr.Zero);
How can I change the width of the row headers or hide them
You can get at the width and visibility of the header row/column through a DataGridTableStyle. DataGridTableStyle has properties such as RowHeadersVisible and RowHeadersWidth. DataGridTableStyle also controls things like selections colors and GridLine styles. // Create a table style that will hold the new column style // that we set and also tie it to our customer’s table from our DB DataGridTableStyle tableStyle = new DataGridTableStyle(); tableStyle.MappingName = ‘customers’; //hide the column headers tableStyle.ColumnHeadersVisible = false; //change width of the row headers tableStyle.RowHeadersWidth = 100; // make the dataGrid use our new tablestyle and bind it to our table dataGrid1.TableStyles.Clear(); dataGrid1.TableStyles.Add(tableStyle);
How do you persist any object in the registry
To store an object in the registry, the object should be serializable (either has a Serializable attribute attached to it or derives from ISerializable; same holds to all contained objects). ArrayList names; // Source object; Can contain any object that is serializable … // Fill up this arraylist BinaryFormatter formatter = new BinaryFormatter(); MemoryStream stream1 = new MemoryStream(); formatter.Serialize(stream1, names); RegistryKey regKey; … // Open the key where you want to store it, with write permissions regKey.SetValue(‘ValueName’, stream1.ToArray()); To Read from registry: ArrayList names; // Destination object RegKey regKey; … // Open the corresponding key BinaryFormatter formatter = new BinaryFormatter(); MemoryStream stream1 = new MemoryStream(); byte[] barray1 = null; barray1 = (byte[])regKey.GetValue(‘ValueName’); if(barray1 != null) { stream1.Write(barray1, 0, barray1.Length); MemoryStream stream1 = new MemoryStream(); byte[] barray1 = null; barray1 = (byte[])regKey.GetValue(‘ValueName’); if(barray1 != null) { stream1.Write(barray1, 0, barray1.Length); stream1.Position = 0; names = formatter.Deserialize(stream1) as ArrayList; }