3
Reply

Question about displaying info in a label by selecting an item in a combo box!

Bradley George

Bradley George

Dec 15 2010 10:33 AM
6.7k
I have a combo box that contains 5 items. I have one label on the window. What i would like to do is whenever a user clicks on one of the items in the combobox, text will populate that label. I would like to show information (IP address, etc.) about whichever item is selected. Any help is appreciated. Thanks.

 private void cmbGroups_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
        //Combo box selection changed. Re-bind data 
        string selectedGroup = (string)cmbGroups.SelectedItem; 
        BindGrid(selectedGroup); 
    } 

private void BindGrid(string selectedGroup)
        {
            //Re-bind the grid
            dgPortStatus.DataContext = _dicPortStatus[selectedGroup].Portstatus.DefaultView;

            InitializeColumns();
        }


  private void _UpdatePortStatus()
        {
            string[] files = Directory.GetFiles(System.Configuration.ConfigurationSettings.AppSettings["portStatusDir"], "PortStatus.*");

            foreach (string file in files)
            {

                PortStatus ps = new PortStatus();
                ps.ReadXml(new StreamReader(file));
                //ps.ReadXml(new FileStream(file, FileMode.Open, FileAccess.Read));
                
                if (!_dicPortStatus.ContainsKey(ps.General[0].Group))
                {
                    _dicPortStatus.Add(ps.General[0].Group, ps);
                }

                PortStatus psOrig = _dicPortStatus[ps.General[0].Group];

                foreach (PortStatus.PortstatusRow psr in ps.Portstatus.Rows)
                {
                    DataRow[] drs = psOrig.Portstatus.Select("PortNumber = '" + psr.PortNumber + "'");

                    if (drs.Length == 1)
                    {
                        DateTime curDt = DateTime.Parse(drs[0]["LastUpdateDateTimeUTC"].ToString());
                        DateTime newDt = psr.LastUpdateDateTimeUTC;

                        if (newDt > curDt)
                        {
                            drs[0]["LastUpdateDateTimeUTC"] = newDt;
                        }
                    }
                    else if (drs.Length == 0)
                    {
                        psOrig.Portstatus.ImportRow(psr);
                    }
                    else
                    {
                        throw new Exception("More than one of the same portnumber on PortStatus file: " + file);
                    }
                }
            }

            foreach (string groupName in _dicPortStatus.Keys)
            {
                if (!cmbGroups.Items.Contains(groupName))
                {
                    cmbGroups.Items.Add(groupName);
                    cmbGroups.SelectedItem = groupName;
                }
            }


Answers (3)