ComboBox inside Silverlight DataGrid

Hello All,

How to implement ComboBox inside Silverlight DataGrid. Here I have uploaded a sample Project which would help you all.

Source Code

Happy Coding :)

How to Bind Silverlight ComboBox with Enum

Hello All,

Binding Silverlight ComboBox with Enum. Suppose we have Enum like this:

public enum Schedule
{
     Day = 1,
     Week = 7,
     Month = 30,
     Year = 365
}
 
then how are we going to bind it with ComboBox. Here is the code:

// Returns all the Enums

public static T[] GetEnumValues()
{
       var type = typeof(T);
       if (!type.IsEnum)
       throw new ArgumentException("Type '" + type.Name + "' is not an enum");
       return (from field in type.GetFields()
       where field.IsLiteral
       select (T)field.GetValue(type)).ToArray();
}
 
ComboBox cbo = sender as ComboBox;
var enums = GetEnumValues();
cbo.ItemsSource = enums;

Happy Coding :)

How to find the last identity value inserted in MYSQL

Hello All,


If you are writing an Insert query and what to find out the last inserted ID then here is what you execute to get the last inserted ID.

DECLARE iID INT;
-- Your Insert query goes here and iID will have your last Inserted ID.
SELECT LAST_INSERT_ID() INTO iID;

Hope that helps.

Bullets For Silverlight ListBox

Here is what the output looks like:












While answering a query on silverlight forum, I thought of writing this blog.

Quoting the question as:
How do I add Bullet Points in SilverLight 4.0?
I tried the <ul> </ul> HTML code and it doesn't work. Is there a special code in SilverLight for Bullet Points?

Here is what you can try:

Xaml Code:

<ListBox x:Name="lbMyBullet" VerticalAlignment="Stretch" Margin="5,2,2,2" Height="150" HorizontalAlignment="Stretch" Width="240">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="images/small-arrowblue.png" VerticalAlignment="Center" Height="9" Width="7"></Image>
<TextBlock x:Name="myBulletText" Margin="5,2,0,0" VerticalAlignment="Top" Text="{Binding Path=Name}" ToolTipService.ToolTip="{Binding Path=Name}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

In Code Behind:
 
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
}

ObservableCollection employee = new ObservableCollection();
employee.Add(new Employee() { ID = 1, Name = "Nimish"});
employee.Add(new Employee() { ID = 2, Name = "Vikas"});
employee.Add(new Employee() { ID = 3, Name = "Pooja"});
employee.Add(new Employee() { ID = 4, Name = "Maya"});
employee.Add(new Employee() { ID = 5, Name = "Kiran"});
employee.Add(new Employee() { ID = 6, Name = "Pragati"});
employee.Add(new Employee() { ID = 7, Name = "Lalit"});
employee.Add(new Employee() { ID = 8, Name = "Neha"});
employee.Add(new Employee() { ID = 9, Name = "Sachin"});
employee.Add(new Employee() { ID = 10, Name = "Ishita"});

lbMyBullet.ItemsSource = employee;

You have to just change the image path.

Happy coding :)