开发者

convert snippet to wpf format combobox

开发者 https://www.devze.com 2023-02-10 02:06 出处:网络
I developed a web app and it contains a portion where i populate combobox using an xml file. Now I am required to develop WPF app that does the same thing using the same xml file.

I developed a web app and it contains a portion where i populate combobox using an xml file. Now I am required to develop WPF app that does the same thing using the same xml file.

My question is this: Can I reuse the code snippet as shown with some modifications? How do I modify it? I understand I cannot use .DataTextField .DataSource and .DataBind since I cannot use the System.Web namespaces

public void PopulateDDLFromXMLFile()
{
    DataSet ds = new DataSet();
    ds.ReadXml("C:\abc.xml");


    DataView dv = ds.Tables["builder"].DefaultView;
    DataView dw = ds.Tables["manager"].DefaultView;

    dv.Sort = "value";

    comboBox1.DataTextField = "value";
    comboBox2.DataTextField = "value";
    comboBox1.DataSource = dv;
    comboBox1.DataBind();
    comboBox2.DataSource = dw;
    comboBox2.D开发者_StackOverflow中文版ataBind();

}


Not quite sure but i think it'd have to be something going in that direction:

    public void PopulateDDLFromXMLFile()
    {
        DataSet ds = new DataSet();
        ds.ReadXml("C:\abc.xml");


        DataView dv = ds.Tables["builder"].DefaultView;
        DataView dw = ds.Tables["manager"].DefaultView;

        dv.Sort = "value";

        comboBox1.ItemsSource = dv; //Sets the collection of items from which to populate
        comboBox2.ItemsSource = dw;

        comboBox1.DisplayMemberPath = "value"; //Sets the path within an item to use for display
        comboBox2.DisplayMemberPath = "value";
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消