Sunday, May 1, 2011

WPF combo box

XAML Code

<ComboBox Height="23" Margin="69,105,111,0" Name="comboBox1" VerticalAlignment="Top" ItemsSource="{Binding StoreTypeTable}" DisplayMemberPath="StoreTypeName" SelectedValuePath="StoreTypeName"  IsSynchronizedWithCurrentItem="True" SelectedIndex="0"/>

C# Code:

My Class:

class StoreTypes:nuClass
{
   private WSOntsu.ServiceSoapClient _WS;
   private WSOntsu.OSM007StoreType _DS;

   public StoreTypes()
   {
        try
        {
            _WS = new WpfOntsu.WSOntsu.ServiceSoapClient();
            _DS = _WS.lstStoreType();

        }
        catch (Exception e)
        {
            bResult = false;
            sResult = e.Message;
        }
             bResult = _DS.Osm007getStoreType.Rows.Count > 0;
   }

    public DataTable StoreTypeTable
    {
        get { return _DS.Osm007getStoreType; }
    }

}

My Page load:

StoreTypes _ST = new StoreTypes();
comboBox1.ItemsSource = _ST.StoreTypeTable.Rows;

How to display combo initial value when page is loading?

plz help me.

From stackoverflow
  • Your request is very unclear. If you want to select the first value in the ComboBox, you can do something like:

    StoreTypes _ST = new StoreTypes();
    comboBox1.ItemsSource = _ST.StoreTypeTable.Rows;
    
    if (comboBox1.Items.Count > 0)
    {
        comboBox1.SelectedIndex = 0;
    }
    

    If that's not what you want, please edit your question.

    HTH, Kent

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.