Nov 18, 2011

NumericTextBox (C#.NET): A TextBox for numbers with built-in mathematical expression evaluation

Update:
The article was updated to the version 1.2. The links are already pointing to the new versions of the files. See details below. 

Introduction
In my project I had a TextBox on one of the forms for entering quantity, and I thought it would be a cool feature if it could understand such basic expressions as 10+42 or 4*8 and so on...
So decided to create a new Control derived from the TextBox, because this could be useful in the future, and now I'm sharing my result.

First of all, since I decided to create a new control, I wanted to make it as flexible as possible, so the expressions that can be understood by the control can include the four basic operations (+, -, *, /) and parentheses, in any valid combination (spaces can be used, they will be skipped).
e.g.: 40+2 or (12+3/ 4) * 4-3*3 or 10+2*(2+5* (4-(2-0.5))+1.5)

Second, I added some extra functionality to the TextBox some are taken from NumericUpDown control, but there are some which I used already but now I built them in the control (changing background color based on value).

Sep 6, 2011

FilterableDataGridView (C#.NET): A DataGridView control with built-in Filtering

During developing my project I was left without Internet access for a week, and I couldn't search for an easy and already written solution for my problem, so I decided to create my own solution.

I had a DataGridView on one of my forms with a DataSource linked to an SQL server through LINQ to SQL and I wanted to be able to filter the result rows, based on user input. Since the clients (the users of my program) will connect to the database through the Internet, some of them via poor connections, I didn't want to make a new query with each change of the filter. I found out that the DataGridViewRow has a Visible property, and it looked like an efficient way to set this according to the filters. So I created a new class inheriting from the DataGridView, and added some extra functionality to support filtering.