public void ReLoadList() { dataGridView1.Rows.Clear(); foreach (SObject soo in conSOs.Values) { int r = dataGridView1.Rows.Add(new DataGridViewRow()); DataGridViewRow dr = dataGridView1.Rows[r]; dr.Cells[0].Value = soo.Name; dr.Cells[1].Value = soo.Tip; dr.Cells[2].Value = soo.TypeName; if (!(soo.Manager.GetSOObject(soo.Name) is SMConnection)) { continue; } SMConnection Con = soo.Manager.GetSOObject(soo.Name) as SMConnection; dr.Cells[3].Value = Con.Simulate ? Con.ConnectionStringSimu : Con.ConnectionString; dr.Cells[4].Value = soo.Auto; dr.Cells[5].Value = Con.Simulate; dr.Cells[6].Value = soo.Status; dr.Tag = soo; } dataGridView1.ClearSelection(); foreach (SObject conSO in conSOs.Values) { //绑定更新事件 conSO.OnUpdate += DoUpdateOne; } }
public void DoUpdateOne(object obj, EventArgs e) { if (this.InvokeRequired) { this.BeginInvoke((EventHandler) delegate { DoUpdateOne(obj, e); }); } else { if (!Visible) { return; } try { SObject soo = obj as SObject; SMConnection Con = so.Manager.GetSOObject(soo.Name) as SMConnection; if (Con != null) { foreach (DataGridViewRow dr in dataGridView1.Rows) { if (dr.Tag.Equals(soo)) { dr.Cells[3].Value = Con.Simulate ? Con.ConnectionStringSimu : Con.ConnectionString; dr.Cells[4].Value = soo.Auto; dr.Cells[5].Value = Con.Simulate; dr.Cells[6].Value = soo.Status; if (soo.Status != null && soo.Status.Contains("..")) { dr.Cells[6].Style.BackColor = Color.LightBlue; } else { dr.Cells[6].Style.BackColor = Color.Empty; } dataGridView1.Refresh(); break; } } } } catch (Exception E) { } } }