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;
dataGridView.TabIndex = snapshotTreeView.TabIndex;
dataGridView.Sorted += DataGridView_Sorted;
dataGridView.Columns[2].DefaultCellStyle.Format = Messages.DATEFORMAT_DMY_HMS;
dataGridView.Columns[2].ValueType = typeof(DateTime);
Date.DefaultCellStyle.Format = Messages.DATEFORMAT_DMY_HMS;
Date.ValueType = typeof(DateTime);
ConnectionsManager.History.CollectionChanged += History_CollectionChanged;
}
void DataGridView_Sorted(object sender, EventArgs e)
{
switch (dataGridView.SortedColumn.Index)
if (dataGridView.SortedColumn.Index == Live.Index)
{
case 0:
sortByTypeToolStripMenuItem.Checked = true;
sortByNameToolStripMenuItem.Checked = false;
sortByCreatedOnToolStripMenuItem.Checked = false;
sortBySizeToolStripMenuItem.Checked = false;
break;
case 1:
sortByTypeToolStripMenuItem.Checked = false;
sortByNameToolStripMenuItem.Checked = true;
sortByCreatedOnToolStripMenuItem.Checked = false;
sortBySizeToolStripMenuItem.Checked = false;
break;
case 2:
sortByTypeToolStripMenuItem.Checked = false;
sortByNameToolStripMenuItem.Checked = false;
sortByCreatedOnToolStripMenuItem.Checked = true;
sortBySizeToolStripMenuItem.Checked = false;
break;
case 3:
sortByTypeToolStripMenuItem.Checked = false;
sortByNameToolStripMenuItem.Checked = false;
sortByCreatedOnToolStripMenuItem.Checked = false;
sortBySizeToolStripMenuItem.Checked = true;
break;
sortByTypeToolStripMenuItem.Checked = true;
sortByNameToolStripMenuItem.Checked = false;
sortByCreatedOnToolStripMenuItem.Checked = false;
sortBySizeToolStripMenuItem.Checked = false;
}
else if (dataGridView.SortedColumn.Index == Snapshot.Index)
{
sortByTypeToolStripMenuItem.Checked = false;
sortByNameToolStripMenuItem.Checked = true;
sortByCreatedOnToolStripMenuItem.Checked = false;
sortBySizeToolStripMenuItem.Checked = false;
}
else if (dataGridView.SortedColumn.Index == Date.Index)
{
sortByTypeToolStripMenuItem.Checked = false;
sortByNameToolStripMenuItem.Checked = false;
sortByCreatedOnToolStripMenuItem.Checked = true;
sortBySizeToolStripMenuItem.Checked = false;
}
else if (dataGridView.SortedColumn.Index == size.Index)
{
sortByTypeToolStripMenuItem.Checked = false;
sortByNameToolStripMenuItem.Checked = false;
sortByCreatedOnToolStripMenuItem.Checked = false;
sortBySizeToolStripMenuItem.Checked = true;
}
}
@ -419,7 +420,7 @@ namespace XenAdmin.TabPages
}
if (dataGridView.SortedColumn == null)
dataGridView.Sort(dataGridView.Columns[1], ListSortDirection.Ascending);
dataGridView.Sort(Snapshot, ListSortDirection.Ascending);
return roots;
}
@ -1215,31 +1216,29 @@ namespace XenAdmin.TabPages
revertButton_Click(sender, e);
}
private void sortByToolStripMenuItem_Click(object sender, EventArgs e)
private void sortByTypeToolStripMenuItem_Click(object sender, EventArgs e)
{
ToolStripMenuItem item = (ToolStripMenuItem)sender;
switch (item.Name)
{
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;
if (!sortByTypeToolStripMenuItem.Checked)
dataGridView.Sort(Live, ListSortDirection.Ascending);
}
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)
{

View File

@ -528,25 +528,25 @@ namespace XenAdmin.TabPages
//
this.sortByNameToolStripMenuItem.Name = "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
//
this.sortByCreatedOnToolStripMenuItem.Name = "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
//
this.sortBySizeToolStripMenuItem.Name = "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
//
this.sortByTypeToolStripMenuItem.Name = "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
//

View File

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