private int FindIndex(GridViewColumnCollection columns, String id) { int index = -1; for (int i = 0; i < columns.Count; i++) { GridViewColumnEx col = columns[i] as GridViewColumnEx; if (col != null) { if (col.Identifier == id) { return(columns.IndexOf(col)); } } } return(index); }
//根据回包动态添加列 public void AddListColumn(string ep, List <ProcessTable> list) { this.Dispatcher.Invoke(() => { ProcessNameList.Clear(); ProcessView.Columns.Clear(); ProcessCheckObj.Clear(); ProcessTypeList.Children.Clear(); //动态生成选择IP列 Tool.XControl.GridViewColumnEx SeleIP = new GridViewColumnEx() { Header = CreateCheckBox("", -1, 0, 0, 0, 0, true), Width = 40, CellTemplate = (DataTemplate)Resources["SelectIP"], }; ProcessView.Columns.Add(SeleIP); //动态生成IP列 Tool.XControl.GridViewColumnEx ID = new GridViewColumnEx() { Header = "编号", Width = 150, CellTemplate = (DataTemplate)Resources["ID"] }; ProcessView.Columns.Add(ID); //动态生成IP列 Tool.XControl.GridViewColumnEx IP = new GridViewColumnEx() { Header = "IP地址", Width = 150, CellTemplate = (DataTemplate)Resources["IP"] }; ProcessView.Columns.Add(IP); //添加进程名称列 int i = 1; foreach (var proc in list) { if (i > 5) { continue; } string index = "ProcessNo." + Convert.ToString(i); if (ProcessNameList.Contains(proc.ProcessName.value_)) { continue; } ProcessNameList.Add(proc.ProcessName.value_); Tool.XControl.GridViewColumnEx obj = new GridViewColumnEx() { Header = proc.ProcessName.value_, Width = 150, CellTemplate = (DataTemplate)Resources[index] }; ProcessView.Columns.Add(obj); XControl.XCheckBox obj_cb = CreateCheckBox(proc.ProcessName.value_, proc.ProcessId.value_, 0, 20, 15, 10); obj_cb.Click += new RoutedEventHandler(OnSelectProcess); ProcessTypeList.Children.Add((XControl.XCheckBox)obj_cb); ProcessCheckObjList.Add(obj_cb); i++; } RobotInfoCollect.GetInstance().UpdateProcessTable(ep, list); }); }