Josh-CO Dev

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


Leave a comment

Silverlight Image Source Binding

I figured out something that just happened to be a life saver yesterday. I have been working on a more social tool for my workout tracking program. One thing I wanted was a comment system that would show the user’s profile picture. I spend forever trying to think of a way to loop through the list box. What I ended up with was much more simple:

 Here is the XAML:

<StackPanel Orientation=”Horizontal”>

<Image Grid.Row=”1″ Height=”64″ Source=”{Binding ImagePath}” HorizontalAlignment=”Left” Margin=”5,5,0,0″ x:Name=”imgProfileImage” Stretch=”Fill” VerticalAlignment=”Top” Width=”64″ />

</StackPanel>

The backend code simply sets the ImagePath binding to a path that is stored in the database.

 

Advertisements


Leave a comment

.NET – Querying data from a binding source

Rather than write code that is chatty with the database, it is possible to pull all the data that your user could ever need from a table or procedure and store it in a dataset. Normally you would then drop in a binding source to link up your datagrid and the dataset. In some cases, you may want to search the data in the grid to find a particular piece of data. Maybe you want to give your users the ability to enter a value in a search box and navigate directly to that record. Using the binding source, this is as simple as two lines of code.

Here it is:

int itemFound = bindingSource.Find(”Field”, Convert.ToInt32 (ValueToFind));

bindingSource.Position = itemFound;


Leave a comment

.NET – Filtering on a BindingSource

So here is another cool trick that I picked up recently. It is incredibly simple to filter on a binding source. Using this code, you can pull all the data back into a DataGrid, other other tool, and then let the users filter the data using the binding source. Thus, you can delimit the data without making subsequent calls to the database.

Here’s the code:

BingingSource.Filter = “FieldName= “Variable + “AND FieldName2= ” + Variable2;