rankep on Programming

Mostly C# – .NET development

ForEach derived type elements in an IEnumerable collection

leave a comment »

Introduction

This post will provide an extension method for the IEnumerable<T> and IEnumerable interface to perform an action on each element which belong to a derived type of T. Using this method you can invoke actions on a part of a collection with just one line of code.

Read the rest of this entry »

Written by Akos Orban

May 7, 2012 at 12:07 pm

MathsEvaluator

leave a comment »

I wrote an article about the MathsEvaluator class, that I made for the NumericTextBox control, on codeproject.com.

I explain in details how I created the parser and how it’s working.

Any reviews are welcome here as well as on CodeProject.

Written by Akos Orban

December 13, 2011 at 11:18 am

FilterableDataGridView (C#.NET)

leave a comment »

Introduction

While 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 SQLserver 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.

My solution consists of two classes:

  1. FilterItem
  2. FilterableDataGridView
Read the rest of this entry »

Written by Akos Orban

December 13, 2011 at 11:13 am

Posted in .NET, C#, database, programming

NumericTextBox (C#.NET)

with one comment

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 I 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. See an example on the following screenshot:

A screenshot of the NumericTextBox control in action

First of all, since I decided to create a new control, I wanted to make it as flexible as possible, so the expressionsthat 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).

Read the rest of this entry »

Written by Akos Orban

December 13, 2011 at 10:43 am

Follow

Get every new post delivered to your Inbox.