本文介绍了如何在选择combobo1值时获得combobox2中的确切数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个组合框在combobo1我有医院的数据和医院用户连接到组合框但是当我运行的时候我得不到确切的用户名单,这些用户都在某些重点下,我们怎样才能得到相同的



我尝试过:




I have two comboboxes were in combobo1 i have data of hospitals and linked hospital users to combobox but while i running the outpit i amnot getting exact list of users who all under certain hopspital, how can we get the same

What I have tried:

void CmbHospitalsSelectedIndexChanged(object sender, EventArgs e)
		{
			            try
            {
                
                //string tag = ((KeyValuePair< string, string >)cmbHospitals.SelectedItem).Key; 
               //MessageBox.Show(tag);            
               // var s=cmbHospitals.SelectedItem;
                //MessageBox.Show(s.key);
                //For Hospital users Dropdown Clear Start
                   dynamic refobj = cmbHospitals.SelectedItem;
                    int key=(int) refobj.Key;
                    Text= Text+cmbhusers.DisplayMember;
                    
					//MessageBox.Show(refobj.Key);
                    cmbhusers.SelectedIndex = -1;
                    cmbhusers.Items.Clear();

                // End Clear
                if(true)
                {
                    WebClient wc = new WebClient();
                    wc.Headers["Content-type"] = "application/x-www-form-urlencoded";
                    NameValueCollection collection = new NameValueCollection();
                    collection.Add("hid",cmbHospitals.SelectedIndex.ToString());
                    collection.Add("sno", "4");
                    byte[] bret = wc.UploadValues(URLAuth, collection);
                    string sret = "";
                    sret = System.Text.Encoding.ASCII.GetString(bret);
                    int count=0;
                    string[,] husers ;                
                   
                     if (sret != "")
                    {                       
                        XmlDocument readDoc = new XmlDocument();
                        readDoc.LoadXml(sret);
                        count = readDoc.SelectNodes("hospitalusers/huids").Count;
                        husers = new string[count, 2];      
                         // alternately, _doc.Load( _strFilename); to read from a file.
                        XmlNodeList xhuid = readDoc.GetElementsByTagName("huid");
                        XmlNodeList xuser_name = readDoc.GetElementsByTagName("user_name");
                        for (int i= 0; i < count; i++)
                        {
                            husers[i,0] = xhuid[i].InnerText;
                            husers[i, 1] = xuser_name[i].InnerText;
                        }
                           cmbhusers.DisplayMember="text";
                             cmbhusers.ValueMember="key";    
                             
                        for (int i = 0; i < husers.GetLength(0); i++)
                        {
                            cmbhusers.Items.Add(new { text = husers[i, 1], key=Convert.ToInt16(husers[i,0])});
                        }
                     }
                }
            }

推荐答案

dynamic refobj = cmbhpd.SelectedItem;
                   int key=(int) refobj.Key;


这篇关于如何在选择combobo1值时获得combobox2中的确切数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 19:55