Monthly Archives: October 2012

Use a for loop to recursively iterate over the items in an array with an unknown number of dimensions in C#

When it starts, the program executes the following code. private void Form1_Load(object sender, EventArgs e) { string[, ,] values = { { { “(0, 0, 0)”, “(0, 0, 1)”, “(0, 0, 2)”, “(0, 0, 3)”, }, { “(0, 1, 0)”, … Continue reading

Posted in algorithms, arrays, syntax | 2 Comments

Make an extender provider that makes it easy to preview TextBox changes in C#

The last few posts explained how to preview changes to a TextBox and ensure that the user could only enter an integer or a floating point value. Those examples demonstrated a basic technique but were hard-wired to specific TextBoxes so … Continue reading

Posted in controls, user interface | Leave a comment

Make a TextBox that lets the user only enter floats in C#

The posts Make a TextBox let the user enter only integers in C# and Make a TextBox let the user enter only integers in C#, Part 2 show how you can make a TextBox accept only integers. This example is … Continue reading

Posted in controls | Leave a comment

Make a TextBox that lets you preview and cancel changes to its text in C#, Part 2

Part 1 of this post explained how the example previews changes made by keyboard events. It then accepts or cancels the changes depending on whether the TextBox’s new value is a valid integer (or the start of one as in … Continue reading

Posted in controls | Leave a comment

Make a TextBox that lets you preview and cancel changes to its text in C#

One of the most annoying omissions in the Windows Forms controls is a way to validate changes to a TextBox before they occur. For example, suppose you want the user to enter a floating point value in a TextBox. The … Continue reading

Posted in controls, user interface | Leave a comment

Select a TreeView subtree when the user selects a node in C#

Sometimes it’s useful to let the user select a subtree in a TreeView control by clicking a higher-level branch. Then the user can deselect individual nodes within the subtree if desired. For example, in the picture shown here I checked … Continue reading

Posted in controls | 4 Comments

Expand a TreeView node’s subtree in C#

A program can call a TreeView node’s EnsureVisible method to expand all of the nodes above it in the tree, but there is no simple method to expand an entire subtree below a node. This example uses the following ExpandNode … Continue reading

Posted in controls | 2 Comments

Solution: Zero rows and columns in an array in C#

This post gives four solutions to Puzzle: Zero rows and columns in an array in C#. If you want to try the puzzle for yourself, see that post before you read this one. This is a fairly long post but … Continue reading

Posted in arrays, games | 3 Comments

Use methods provided by the Array class in C#

The example Use the Array class’s Sort and BinarySearch methods in C# shows how to use two useful methods provided by the Array class. This example demonstrates some other useful methods provided by the Array class. For simplicity, this example … Continue reading

Posted in arrays, classes | Leave a comment

Puzzle: Zero rows and columns in an array in C#

This puzzle is given as a coding example in the book Cracking the Coding Interview by Gayle Laakmann McDowell. (I’ll post a review later after I’ve finished going through it.) The puzzle is: Write an algorithm such that if an … Continue reading

Posted in arrays, games | Leave a comment