Josh-CO Dev

Solving the worlds problems one line of code at a time.

Leave a comment

.NET – 2 way databinding via a binding source

One thing that I have always loved about Delphi is how well all the controls play together and the flexibility that you have through the visual designer. Data binding to controls is a cinch. You can drop in a query object and then tie it to a dataset. You can then bind anything to this dataset, such as a grid and several drop downs. When you click on a row, it will show the value in the corresponding drop down boxes as well.

In .NET, this is much harder to accomplish using an N-Tier framework. I discovered the other day that when using binding sources you can accomplish this by using just one extra line of code:

textBox.DataBindings.Add(new Binding("Text", BindingSource, "Field_name", true));

Piece of cake! Now when any other object that is bound to this dataset is selected, generally a grid, the text in the textbox will update to the contents of the dataset.


Leave a comment

XNA – Simple Collision Detection

Here is some incredibly simple code to check for collisions. The method is accepting an x and a y coordinate. The for loop then loops through each object on the screen and checks first to see if the x value is within the x-range of the object. If that check returns true, it performs the same check against the y-range. If all checks are true, we remove the object from the list so it will no longer be drawn and increase the score.

Continue reading