Real Test Driven Development – Thinking of Money 12

It took a while to figure out correctly but by adding the grid to the form and opening the data grid view task, I selected the object data source

and then clicked next, ok so we want to display money engine transactions, this is important, what we are selecting on this screen is the row item we are going to display, this took me a bit of time to get my head around, it helped me to see it as defining the columns that would be displayed, first select the transaction object, which has all the properties of a transaction, and click next

press finish with money transactions selected, and you are returned to the main form, but this time the grid has all the basic column names filled out, now we need to edit the grid column names so that only the ones we are interested in are shown.

So now with this basic configuration done its back to the code.

when I was trying out this I used a new form and simply dropped the datagrid onto in, and set it up to fill the form, I wanted to quickly understand the binding technique, and what code was required to bind the collection to the form, this ended up as follows

       public Form1()

            MoneyEngine.MoneyEngine engine = new MoneyEngine.MoneyEngine();

            dataGridView1.DataSource = engine.History;

it turned out that simply loading the money engine, and then binding the engine history, which is a collection of transactions, this automatically fills the grid, like so

having tested the theory we setup the main gird on the money form the same way, however in keeping with our wish to test as much as possible, we will move the binding code into a controller module, which we can test in the usual way, 

know I did all of this without running any unit tests, but sometimes I find its easier just to breakout a quick form and try out some quick code, especially when it involves using Visual Studio wizards.  As long as when we transfer the code into the main project, we create tests that will ensure that it works and any changes are caught things should be fine.

which we shall do next time.


About Duncan Butler

Trying to be a very agile software developer, working in C# with Specflow, Nunit and Machine Specifications, and in the evening having fun with Ruby and Rails
This entry was posted in Projects. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s