Ссылка на объект не добавлена(combobox)C#
привет,
я написал ниже код,где будет выполняться i am getting exception object reference not added to instance, пожалуйста, помогите, как пройти через него.
Что я уже пробовал:
void CmbhospitalsSelectedIndexChanged(object sender, EventArgs e) { try { WebClient wc = new WebClient(); wc.Headers["Content-type"] = "application/x-www-form-urlencoded"; NameValueCollection collection = new NameValueCollection(); collection.Add("hid","0"); collection.Add("sno", "2"); byte[] bret = wc.UploadValues(URLAuth, collection); string sret = ""; sret = System.Text.Encoding.ASCII.GetString(bret); int count=0; string[,] hospitalslist ; if (sret != "") { XmlDocument readDoc = new XmlDocument(); readDoc.LoadXml(sret); count = readDoc.SelectNodes("hoskeys/hkids").Count; hospitalslist = new string[count, 2]; // alternately, _doc.Load( _strFilename); to read from a file. XmlNodeList xhkid = readDoc.GetElementsByTagName("hkid"); XmlNodeList xhos_key = readDoc.GetElementsByTagName("hos_key"); for (int i= 0; i <count; i++) { hospitalslist[i, 0] = xhkid[i].InnerText; hospitalslist[i, 1] = xhos_key[i].InnerText; } for (int i = 0; i < hospitalslist.GetLength(0); i++) { cmbhusers.Items.Add(new { Text = hospitalslist[i, 1], Key=Convert.ToInt16(hospitalslist[i, 0]) }); } cmbhusers.DisplayMember = "Text"; cmbhusers.ValueMember = "Key"; } } catch (Exception e1) { MessageBox.Show(e1.Message); } }