Using Combobox In CustomActivity RRS feed

  • Question

  • hi all ,

    myselft rajendra, i wanted to write a custom activity to run new workflow from it and it should have a combox to select the workflow and i am binding the combox with the data from batabase.

    things to work:

    when i select a value in combobox, InArgument in the property grid need to be updated.

    i have done with the IValueConverter Part which is not being called when i select any value from combobox  when i databind the combobox.

    Having SelectedItem Property as below

    SelectedItem="{Binding Path=ModelItem.SecItem, Mode=TwoWay, Converter={StaticResource comboconverter} }"

     but it is working when i hardcode the comboboxitems , help me where i am going wrong i am new to both wpf and wf4.0.

    Here i am providing my code :

    //SecItem find in ModelItem.SecItem is the InArgument<string> Declared in CustomActivity derived from CodeActivity

    <sap:ActivityDesigner x:Class="ActivityDesignerLibrary3.ActivityDesigner1"








    <loc:CombooxToArgConveter x:Key="comboconverter"/>



    <Grid Height="151" Width="372" x:Name="Grid1">





    <ComboBox Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="4,22,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" SelectedItem="{Binding Path=ModelItem.SecItem, Mode=TwoWay, Converter={StaticResource comboconverter} }" Loaded="comboBox1_Loaded" ItemsSource="{Binding}" SelectedIndex="0" SelectionChanged="comboBox1_SelectionChanged">




     Code in  ActivityDesigner1.xaml.cs:

    namespace ActivityDesignerLibrary3


    public partial class ActivityDesigner1


    SqlConnection sqlCon;

    SqlCommand cmd;

    SqlDataAdapter sqlDa;

    System.Data.DataSet ds;

    public ActivityDesigner1()



    // i am getting the problem when i databind the combobox


    //i am able to change the InArgument in property grid with hardcoded values





    private void ListWorkflows()


    sqlCon = new SqlConnection();

    sqlCon.ConnectionString = "Data Source=ip address here...; Database=databasename; user id=sa; password=password";

    cmd = new SqlCommand();

    cmd.CommandType = CommandType.Text;

    cmd.CommandText = "select * from dbo.Workflows";

    cmd.Connection = sqlCon;

    sqlDa = new SqlDataAdapter();

    sqlDa.SelectCommand = cmd;

    ds = new DataSet();



    sqlDa.Fill(ds, "workflows");

    Grid1.DataContext = ds.Tables["workflows"].DefaultView;


    comboBox1.DisplayMemberPath =


    //comboBox1.SelectedValuePath = ds.Tables["workflows"].Columns["id"].ToString();



    catch (Exception ex)







     IValueConverter Code:

    public class CombooxToArgConveter : IValueConverter


    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)


    // Convert InArgument<string> to Combo box value

    //MessageBox is Used to debug my IValueConverter Code

    MessageBox.Show("Convert "+value.ToString());

    ModelItem modelItem = value as ModelItem;

    if (value != null)


    InArgument<string> inArgument = modelItem.GetCurrentValue() as InArgument<string>;

    MessageBox.Show("Convert " + inArgument.ToString());

    if (inArgument != null)


    Activity<string> expression = inArgument.Expression;

    VisualBasicValue<string> vbexpression = expression as VisualBasicValue<string>;

    Literal<string> literal = expression as Literal<string>;

    if (literal != null)


    MessageBox.Show("Convert " + "\"" + literal.Value + "\"");

    return "\"" + literal.Value + "\"";


    else if (vbexpression != null)


    MessageBox.Show("Convert " + vbexpression.ExpressionText);

    return vbexpression.ExpressionText;


    }return null;


    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)


    {MessageBox.Show("ConvertBack " + value.ToString());

    string itemContent = value.ToString();//(string)((ComboBoxItem)value).Content;

    VisualBasicValue<string> vbArgument = new VisualBasicValue<string>(itemContent);

    InArgument<string> inArgument = new InArgument<string>(vbArgument);

    return inArgument;

     }catch (Exception ex)

    {MessageBox.Show("ConvertBack Exception "+ex.Message);return "exception";







    Monday, March 22, 2010 7:15 AM

All replies

  • I think you might want to look at the SelectedValue or SelectedValuePath options for binding the combo box instead of SelectedItem.

    How To link: http://msdn.microsoft.com/en-us/library/ms788714.aspx 

    (This reminds me of a scenario of dynamically populating combo box reminds me of I tried where I wanted to bind the set of combo box values to a list of arguments of the whole workflow. I also hit some problems related to the dynamic combo box population, and problems specific to ModelItemCollection, but I am guessing those mostly might not apply here )


    Thursday, July 8, 2010 5:25 AM