CA-248353: Do not use a hardcoded string or integer to reference DataGridView columns or ToolStripMenuItems.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2018-05-01 15:58:14 +01:00 committed by Mihaela Stoica
parent 7cc1402099
commit 085b4d4f6e
3 changed files with 53 additions and 54 deletions

View File

@ -78,40 +78,41 @@ namespace XenAdmin.TabPages
base.Text = Messages.SNAPSHOTS_PAGE_TITLE; base.Text = Messages.SNAPSHOTS_PAGE_TITLE;
dataGridView.TabIndex = snapshotTreeView.TabIndex; dataGridView.TabIndex = snapshotTreeView.TabIndex;
dataGridView.Sorted += DataGridView_Sorted; dataGridView.Sorted += DataGridView_Sorted;
dataGridView.Columns[2].DefaultCellStyle.Format = Messages.DATEFORMAT_DMY_HMS; Date.DefaultCellStyle.Format = Messages.DATEFORMAT_DMY_HMS;
dataGridView.Columns[2].ValueType = typeof(DateTime); Date.ValueType = typeof(DateTime);
ConnectionsManager.History.CollectionChanged += History_CollectionChanged; ConnectionsManager.History.CollectionChanged += History_CollectionChanged;
} }
void DataGridView_Sorted(object sender, EventArgs e) void DataGridView_Sorted(object sender, EventArgs e)
{ {
switch (dataGridView.SortedColumn.Index) if (dataGridView.SortedColumn.Index == Live.Index)
{ {
case 0: sortByTypeToolStripMenuItem.Checked = true;
sortByTypeToolStripMenuItem.Checked = true; sortByNameToolStripMenuItem.Checked = false;
sortByNameToolStripMenuItem.Checked = false; sortByCreatedOnToolStripMenuItem.Checked = false;
sortByCreatedOnToolStripMenuItem.Checked = false; sortBySizeToolStripMenuItem.Checked = false;
sortBySizeToolStripMenuItem.Checked = false; }
break; else if (dataGridView.SortedColumn.Index == Snapshot.Index)
case 1: {
sortByTypeToolStripMenuItem.Checked = false; sortByTypeToolStripMenuItem.Checked = false;
sortByNameToolStripMenuItem.Checked = true; sortByNameToolStripMenuItem.Checked = true;
sortByCreatedOnToolStripMenuItem.Checked = false; sortByCreatedOnToolStripMenuItem.Checked = false;
sortBySizeToolStripMenuItem.Checked = false; sortBySizeToolStripMenuItem.Checked = false;
break; }
case 2: else if (dataGridView.SortedColumn.Index == Date.Index)
sortByTypeToolStripMenuItem.Checked = false; {
sortByNameToolStripMenuItem.Checked = false; sortByTypeToolStripMenuItem.Checked = false;
sortByCreatedOnToolStripMenuItem.Checked = true; sortByNameToolStripMenuItem.Checked = false;
sortBySizeToolStripMenuItem.Checked = false; sortByCreatedOnToolStripMenuItem.Checked = true;
break; sortBySizeToolStripMenuItem.Checked = false;
case 3: }
sortByTypeToolStripMenuItem.Checked = false; else if (dataGridView.SortedColumn.Index == size.Index)
sortByNameToolStripMenuItem.Checked = false; {
sortByCreatedOnToolStripMenuItem.Checked = false; sortByTypeToolStripMenuItem.Checked = false;
sortBySizeToolStripMenuItem.Checked = true; sortByNameToolStripMenuItem.Checked = false;
break; sortByCreatedOnToolStripMenuItem.Checked = false;
sortBySizeToolStripMenuItem.Checked = true;
} }
} }
@ -419,7 +420,7 @@ namespace XenAdmin.TabPages
} }
if (dataGridView.SortedColumn == null) if (dataGridView.SortedColumn == null)
dataGridView.Sort(dataGridView.Columns[1], ListSortDirection.Ascending); dataGridView.Sort(Snapshot, ListSortDirection.Ascending);
return roots; return roots;
} }
@ -1215,31 +1216,29 @@ namespace XenAdmin.TabPages
revertButton_Click(sender, e); revertButton_Click(sender, e);
} }
private void sortByTypeToolStripMenuItem_Click(object sender, EventArgs e)
private void sortByToolStripMenuItem_Click(object sender, EventArgs e)
{ {
ToolStripMenuItem item = (ToolStripMenuItem)sender; if (!sortByTypeToolStripMenuItem.Checked)
switch (item.Name) dataGridView.Sort(Live, ListSortDirection.Ascending);
{
case "sortByTypeToolStripMenuItem":
dataGridView.Sort(dataGridView.Columns[0], ListSortDirection.Ascending);
dataGridView.Columns[0].HeaderCell.SortGlyphDirection = SortOrder.Ascending;
break;
case "sortByNameToolStripMenuItem":
dataGridView.Sort(dataGridView.Columns[1], ListSortDirection.Ascending);
break;
case "sortByCreatedOnToolStripMenuItem":
dataGridView.Sort(dataGridView.Columns[2], ListSortDirection.Ascending);
break;
//case "sortBySizeToolStripMenuItem":
// DataGridView.Sort(DataGridView.Columns[3], ListSortDirection.Ascending);
// break;
}
if (item.Name != "sortByTypeToolStripMenuItem")
dataGridView.Columns[0].HeaderCell.SortGlyphDirection = SortOrder.None;
} }
private void sortByNameToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!sortByNameToolStripMenuItem.Checked)
dataGridView.Sort(Snapshot, ListSortDirection.Ascending);
}
private void sortByCreatedOnToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!sortByCreatedOnToolStripMenuItem.Checked)
dataGridView.Sort(Date, ListSortDirection.Ascending);
}
private void sortBySizeToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!sortBySizeToolStripMenuItem.Checked)
dataGridView.Sort(size, ListSortDirection.Ascending);
}
private void screenshotPictureBox_Click(object sender, EventArgs e) private void screenshotPictureBox_Click(object sender, EventArgs e)
{ {

View File

@ -528,25 +528,25 @@ namespace XenAdmin.TabPages
// //
this.sortByNameToolStripMenuItem.Name = "sortByNameToolStripMenuItem"; this.sortByNameToolStripMenuItem.Name = "sortByNameToolStripMenuItem";
resources.ApplyResources(this.sortByNameToolStripMenuItem, "sortByNameToolStripMenuItem"); resources.ApplyResources(this.sortByNameToolStripMenuItem, "sortByNameToolStripMenuItem");
this.sortByNameToolStripMenuItem.Click += new System.EventHandler(this.sortByToolStripMenuItem_Click); this.sortByNameToolStripMenuItem.Click += new System.EventHandler(this.sortByNameToolStripMenuItem_Click);
// //
// sortByCreatedOnToolStripMenuItem // sortByCreatedOnToolStripMenuItem
// //
this.sortByCreatedOnToolStripMenuItem.Name = "sortByCreatedOnToolStripMenuItem"; this.sortByCreatedOnToolStripMenuItem.Name = "sortByCreatedOnToolStripMenuItem";
resources.ApplyResources(this.sortByCreatedOnToolStripMenuItem, "sortByCreatedOnToolStripMenuItem"); resources.ApplyResources(this.sortByCreatedOnToolStripMenuItem, "sortByCreatedOnToolStripMenuItem");
this.sortByCreatedOnToolStripMenuItem.Click += new System.EventHandler(this.sortByToolStripMenuItem_Click); this.sortByCreatedOnToolStripMenuItem.Click += new System.EventHandler(this.sortByCreatedOnToolStripMenuItem_Click);
// //
// sortBySizeToolStripMenuItem // sortBySizeToolStripMenuItem
// //
this.sortBySizeToolStripMenuItem.Name = "sortBySizeToolStripMenuItem"; this.sortBySizeToolStripMenuItem.Name = "sortBySizeToolStripMenuItem";
resources.ApplyResources(this.sortBySizeToolStripMenuItem, "sortBySizeToolStripMenuItem"); resources.ApplyResources(this.sortBySizeToolStripMenuItem, "sortBySizeToolStripMenuItem");
this.sortBySizeToolStripMenuItem.Click += new System.EventHandler(this.sortByToolStripMenuItem_Click); this.sortBySizeToolStripMenuItem.Click += new System.EventHandler(this.sortBySizeToolStripMenuItem_Click);
// //
// sortByTypeToolStripMenuItem // sortByTypeToolStripMenuItem
// //
this.sortByTypeToolStripMenuItem.Name = "sortByTypeToolStripMenuItem"; this.sortByTypeToolStripMenuItem.Name = "sortByTypeToolStripMenuItem";
resources.ApplyResources(this.sortByTypeToolStripMenuItem, "sortByTypeToolStripMenuItem"); resources.ApplyResources(this.sortByTypeToolStripMenuItem, "sortByTypeToolStripMenuItem");
this.sortByTypeToolStripMenuItem.Click += new System.EventHandler(this.sortByToolStripMenuItem_Click); this.sortByTypeToolStripMenuItem.Click += new System.EventHandler(this.sortByTypeToolStripMenuItem_Click);
// //
// sortToolStripSeparator // sortToolStripSeparator
// //

View File

@ -230,7 +230,7 @@ namespace XenAdmin.Wizards.ImportWizard
AddVIFRow(vif); AddVIFRow(vif);
} }
m_networkGridView.Sort(m_networkGridView.Columns[0], ListSortDirection.Ascending); m_networkGridView.Sort(NameNetworkColumn, ListSortDirection.Ascending);
} }
finally finally
{ {