两个Combo box组合框控件关联xml中的数据
发布时间:2020-12-15 23:20:39 所属栏目:百科 来源:网络整理
导读:仅为初学者提供。 1、在xml文件中,有如下关系: ShopsShop NO="0" Name="山东省"UnitsUnit NO="0"济南/UnitUnit NO="1"青岛/UnitUnit NO="2"潍坊/UnitUnit NO="3"烟台/Unit/Units/ShopShop NO="1" Name="湖南省"UnitsUnit NO="0"长沙/UnitUnit NO="1"张家界
仅为初学者提供。 1、在xml文件中,有如下关系: <Shops> <Shop NO="0" Name="山东省"> <Units> <Unit NO="0">济南</Unit> <Unit NO="1">青岛</Unit> <Unit NO="2">潍坊</Unit> <Unit NO="3">烟台</Unit> </Units> </Shop> <Shop NO="1" Name="湖南省"> <Units> <Unit NO="0">长沙</Unit> <Unit NO="1">张家界</Unit> <Unit NO="2">益阳</Unit> </Units> </Shop> </Shops>2、在初始化函数中,添加如下代码 3、然后在第一个组合框控件的消息响应函数中添加如下代码,可以使第一个改变的同时,第二个对应的改变: void CDlgUnit::OnSelchangeShop() { // TODO: Add your control notification handler code here ((CComboBox*)GetDlgItem(IDC_UNIT))->ResetContent(); CString strShop; int i=((CComboBox*)GetDlgItem(IDC_SHOP))->GetCurSel(); ((CComboBox*)GetDlgItem(IDC_SHOP))->GetLBText(i,strShop); CMarkup xml;//CMarkup是有关xml文件的解读,网上有文件,可以直接使用。 xml.Load(GetCurDir()+_T("123.INI"));//123.INI是xml文件的名称。 xml.ResetPos(); xml.FindChildElem(); xml.IntoElem(); xml.FindElem(_T("Shops")); xml.IntoElem(); while(xml.FindElem()){ if(xml.GetAttrib(_T("Name"))==strShop) { xml.IntoElem(); xml.FindElem(_T("Units")); xml.IntoElem(); while(xml.FindElem()){ ((CComboBox*)GetDlgItem(IDC_UNIT))->AddString(xml.GetData()); } ((CComboBox*)GetDlgItem(IDC_UNIT))->SetCurSel(0); break; } } }以上仅供参考。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |