请解决这个问题 [英] plz solve this question

查看:62
本文介绍了请解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题

如何从一个Xml文件绑定父子组合框".将选择一个组合框第二个组合框.

这是xml文件

Here is the questions

how to bind Parent And Child Combobox from one Xml file .Selecion of one Combobox second Combobox will be selected.

here is the xml file

<?xml version="1.0" encoding="utf-8"?>
<Countries>
   <Country Id="1" Name="India">
     <State>
        <SId>1</SId>
        <SName>Maharashtra</SName>
     </State>
    <State>
       <SId>2</SId>
       <SName>Gujarat</SName>
    </State>
      <State>
         <SId>3</SId>
         <SName>Delhi</SName>
      </State>
     <State>
         <SId>4</SId>
         <SName>Uttar Pradesh</SName>
     </State>
       <State>
         <SId>5</SId>
         <SName>Kerala</SName>
       </State>
     <State>
       <SId>6</SId>
       <SName>Jammu and Kashmir</SName>
     </State>
  </Country>
<Country Id="2" Name="Pakistan">
     <State>
       <SId>1</SId>
       <SName>Lahore</SName>
     </State>
  <State>
     <SId>2</SId>
     <SName>Rawalpindi</SName>
  </State>
  <State>
    <SId>3</SId>
    <SName>Karachi</SName>
  </State>
     <State>
       <SId>4</SId>
       <SName>Islamabad</SName>
     </State>
  <State>
    <SId>5</SId>
    <SName>Multan</SName>
  </State>
  </Country>
<Country Id="3" Name="Sri Lanka">
     <State>
       <SId>1</SId>
       <SName>Colombo</SName>
     </State>
  <State>
    <SId>2</SId>
    <SName>Kandy</SName>
  </State>
  <State>
    <SId>3</SId>
    <SName>Galle</SName>
  </State>
     <State>
       <SId>4</SId>
       <SName>Anuradhapura</SName>
     </State>
  <State>
    <SId>5</SId>
    <SName>Ratnapura</SName>
  </State>
   </Country>
</Countries>

推荐答案

这里是phoolchand的解决方案

Here is the solution by phoolchand

namespace WinformswithXml
{
    public partial class Form4 : Form
    {
        string xmlfile = "D:\\phoolchand\\Country.xml";
        DataSet ds = new DataSet();

        public Form4()
        {
            InitializeComponent();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            
            DataView dv,dv1;
            

            ds.ReadXml(xmlfile);
            dv = new DataView(ds.Tables[0]);
            cboCountry .DataSource = dv;
            cboCountry.DisplayMember = "Name";
            cboCountry.ValueMember = "Country_Id";

            dv1 = new DataView(ds.Tables[1]);
            dv1.RowFilter = "Country_Id=" + cboCountry.SelectedValue.ToString();
            cbostate.DataSource = dv1;
            cbostate.DisplayMember = "SName";
            cbostate .ValueMember = "SId";
           
        }

        private void cboCountry_SelectedIndexChanged(object sender, EventArgs e)
        {
        
            DataView dv1;
            //ds.ReadXml(xmlfile);
            dv1 = new DataView(ds.Tables[1]);
            string str = cboCountry.SelectedValue.ToString();
            if (str != "System.Data.DataRowView" & cboCountry.SelectedIndex != -1)
            {
                dv1.RowFilter = "Country_Id=" + cboCountry.SelectedValue.ToString();
            }
            cbostate.DataSource = dv1;
            cbostate.DisplayMember = "SName";
            cbostate.ValueMember = "SId";
        }
    }
}


这篇关于请解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆