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; } }