internal void SetSelectedObject(ISpatialObject so) { try { editButton.Visible = false; string oldLastPage = m_LastPageName; // Grab the attributes we'll be displaying List <Row> rows = GetRows(so); // Require a page for each attribute, plus 1 for standard properties. // If we have an excess number of property pages, get rid of the redundant ones while (tabControl.TabCount > (1 + rows.Count)) { tabControl.TabPages.RemoveAt(1); } // Reuse any remaining PropertyPages, add any additional pages int toReuse = (tabControl.TabCount - 1); foreach (Row r in rows) { if (toReuse > 0) { PropertyPage pp = (tabControl.TabPages[toReuse] as PropertyPage); Debug.Assert(pp != null); pp.SetRow(r); toReuse--; } else { tabControl.TabPages.Add(new PropertyPage(r)); } } propertyGrid1.SelectedObject = so; // If a non-standard tab was previously on top, and we still have // a page with the same tab text, ensure it's on top. Failing // that, go for the first tab that shows any database attributes // (since that info will likely have more relevance to the user). if (!SelectPage(oldLastPage)) { if (tabControl.TabCount > 1) { tabControl.SelectedIndex = 1; } } } catch { propertyGrid1.SelectedObject = null; } propertyGrid1.Refresh(); }
private void editButton_Click(object sender, EventArgs e) { // Do nothing if the topmost tab page doesn't relate to a database row (the // editing button should have been invisible) PropertyPage pp = (tabControl.SelectedTab as PropertyPage); if (pp == null) { return; } Row r = pp.DisplayedRow; if (AttributeData.Update(r)) { pp.RefreshRow(); } }