1

現在、ボタン用に次のコードがあります。SilverlightApplication2.ServiceReference2.Employeeユーザーが選択したテキスト文字列の代わりに、メッセージ ボックスが表示されます。コンボボックスの項目は、WCF サービスによって設定されています。その結果、非同期呼び出しに渡すことができません。ユーザーが選択した文字列を取得するにはどうすればよいですか?

private void btnAdd_Click(object sender, RoutedEventArgs e)
{
    object selectedItem = comobo1.SelectedItem.ToString();
    MessageBox.Show(selectedItem.ToString());
    var proxy = new Service1Client();
    proxy.GetAllEmployeesCompleted += proxy_GetAllEmployeesCompleted;
    proxy.GetAllEmployeesAsync(selectedItem.ToString());
}

私のサービス参照は次のようになります

パブリック クラス ドロップダウン {

    [OperationContract]
    public ObservableCollection<Employee> GetAllBrands()
    {   

        var empstwo = new ObservableCollection<Employee>();
        string connect = ConfigurationManager.ConnectionStrings["yoyo"].ToString();
        using (var con = new OdbcConnection(connect))

        {  
            //now you can try
            //wait. To accept a param from main page, u need to create a method to accept that param first.
            //I think you should put this in service1.svc.cs

            string query = "Select distinct(brand) FROM pivottable";
            var cmd = new OdbcCommand(query, con);
            con.Open();
            using (var dr = cmd.ExecuteReader())
            {


                while (dr.Read())
                {
                    var emp = new Employee();

                    emp.ComboData = dr.GetStringOrNull(0);

                    empstwo.Add(emp);

                }


            }



        }

        return empstwo;
    }

}

これは従業員クラスです。この文字列で、ComboData はドロップダウン リストに入力するブランドのリストを保持します

public class Employee
{
    public int EmployeeID { get; set; }
    public string FirstName { get; set; }
    public Uri ImageURI { get; set; }
    public string ComboData { get; set; }


}
4

3 に答える 3

0

プロパティを使用できTextます。

string selectedText = comobo1.Text;

ドキュメントから。

現在選択されている項目のテキストを取得または設定します。

于 2014-08-19T03:55:46.000 に答える
0

選択したアイテムを、バインドしているオブジェクトのタイプにキャストする必要があります。このようなもの、

var selected = (Employee)comobo1.SelectedItem;
MessageBox.Show(selected.ComboData.ToString());
于 2014-08-19T03:55:55.387 に答える