Click here to Skip to main content
15,567,466 members
Articles / Desktop Programming / Windows Forms
Posted 17 Jul 2009


12 bookmarked

Rapid Mapping Form

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
17 Jul 2009CPOL3 min read
This article describes a form with two lists. The form is used to drag and drop items from one list to the other and create a "mapping" between items from the lists.
Image 1


This article describes a form with two lists. The form is used to drag and drop items from one list to the other and create a "mapping" between items of the lists.


We were recently developing a utility to facilitate conversion of data from our legacy systems to the new generation of systems. We had the whole thing up and running and then the guy who used it said:

"Why don't you give me a screen with a list of all the old DB tables on the left side and another list of all the new DB tables on the right side and I will just drag a table from one side, drop it on a table on the other side and you will create the mapping."

"Oh, we said, we will have to evaluate the..."

"And while you are at it, why don't you make another screen with the fields from the source table on the left side and..."

"Oh, we said, we get the picture. Let us see what we can do."

Well, since it was indeed a good idea, and since we had metadata for both data bases, we went on and made the "rapid mapping form". As the form is to be reused (event without the golden rule – you never know when you will need it again – we already had two usages) we developed a general form, applicable in any mapping scenario.

Using the Code

The RapindMappingForm has a constructor that takes in an IEnumerable<object> which contains the left side object, an array of string, each the name of a property on the left side object. It takes another set for the right hand side, and a Boolean indicating whether objects mapped should be removed from both sides of the form. The form displays two lists. Each list contains a row for each object in the IEnumerable<object> and a column for each property in the string array. Each time the user creates a mapping, the MappingCreated event is fired and the two objects are supplied as properties of the RapidMappingEventArgs.

RapidMappingForm rapidMappingForm = new RapidMappingForm(
    , new string[] { "Name", "Age" }
    , GetRightList()
    , new string[] {"Name","PetType" }
    , true);
rapidMappingForm.MappingCreated += new RapidMappingEvent(rapidMappingForm_MappingCreated);

The code includes the rapid mapping form and a test project that runs it with or without removing elements after mapping.

Points of Interest

The code is mostly simple Drag and Drop and a little trivial reflection.

Type Safety

As you may have noticed, the list for both sides of the mapping are not type safe. This is a potential problem but it also opens the way for some nice improvisations. Say you are displaying tables metadata on the left hand side of your mapping form and you want to add an option of "Create New Table". All you have to do is make an object that has those specific properties you intend to display (hell, it can even be of an anonymous type). You then would have to figure out what to do with your e.LeftObject on the MappingCreated event...
It is most definitely possible to produce a generic version of this form: RapindMappingForm<TLeftList,TRightList> (including the events and all).

Loose Edges

Quality and Documentation

The code was built rapidly, with the intention of serving an in-house tool. It is properly under-designed, under-coded, under-documented and under-tested, though the guy who ordered it is very happy. Use it as an inspiration, after meticulous inspection, or at your own risk.

Mapping Button

Wouldn't it be nice if there was a button that says "Map!" and if it is pressed while an item is selected in both lists, it would invoke the Mapping event?


Aha, it would also be nice to have this in WPF.


  • 17th July, 2009: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Chief Technology Officer Ziv systems, Israel
Israel Israel
Starting with Apple IIe BASICA, and working my way through Pascal, Power Builder, Visual basic (and the light office VBA) C, C++, I am now a full stack developer and development manager. Mostly with MS technologies on the server side and javascript(typescript) frameworks on the client side.

Comments and Discussions

Question1-n relationships? Pin
pinx20-Jul-09 23:11
pinx20-Jul-09 23:11 
AnswerRe: 1-n relationships? Pin
Asher Barak21-Jul-09 1:31
professionalAsher Barak21-Jul-09 1:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.