How do I make a field auto increment as new rows are added to my datagrid
DataTable myTable = new DataTable(‘Customers’); … DataColumn cCustID = new DataColumn(‘CustID’, typeof(int)); cCustID.AutoIncrement = true; cCustID.AutoIncrementSeed = 1; cCustID.AutoIncrementStep = 1; myTable.Columns.Add(cCustID);
I have a form with several controls on it. As I size the form, the controls are being resized continuously. Is it possible to postpone changing the controls position until the resizing is complete
Shawn Burke suggested this solution in a response on the microsoft.public.dotnet.framework.windowsforms newsgroup. The idea is to do the painting on Idle. This means you simple invalidate when being sized and then do your full paint when the size completes. Here is the code that you would add to your form. bool idleHooked = false; protected override void OnResize(EventArgs e) { if (!idleHooked) { Application.Idle += new EventHandler(OnIdle); } } private void OnIdle(object s, EventArgs e) { Invalidate(); PerformLayout(); if (idleHooked) { Application.Idle -= new EventHandler(OnIdle); } }
How can I see what is installed in the Global Assembly on a machine
Use Windows Explorer to view the C:\WINNT\assembly folder. If the .NET Framework is installed, the Windows Explorer will show a custom view of this folder. Use the detailed view to see the details of each assembly.
My program dynamically builds lots of strings. Is there a way to optimize string performance
Use the StringBuilder class to concatenate strings. This class reuses memory. If you add string members to concatenate them, there is extra overhead as new memory is allocated for the new string. If you do a series of concatenations using the strings (instead of StringBuilder objects) in a loop, you continually get new strings allocated. StringBuilder objects allocate a buffer, and reuse this buffer in its work, only allocating new space when the initial buffer is consumed. Here is a typical use case. StreamReader sr = File.OpenText(dlg.FileName); string s = sr.ReadLine(); StringBuilder sb = new StringBuilder(); while (s != null) { sb.Append(s); s = sr.ReadLine(); } sr.Close(); textBox1.Text = sb.ToString();
In VB6, I used control arrays to have a common handler handle events from several controls. How can I do this in Windows Forms
You can specify events from different controls be handled by a single method. When you define your handler, you can list several events that are to be handled by listing them in the Handles argument. This statement handles three different textbox’s TextChanged event. Private Sub TextsChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged In the TextsChanged handler, you may need to identify the particular control that fired the event. This sender parameter holds the control. You can use it with code such as: Dim eventTextBox as TextBox = sender