add context menu, reorganize code
This commit is contained in:
parent
567dc6978e
commit
340c3f2dc6
|
|
@ -26,6 +26,7 @@
|
|||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(XMLContentEditor));
|
||||
this.XMLStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
|
|
@ -34,8 +35,12 @@
|
|||
this.partColorsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.XMLView = new System.Windows.Forms.DataGridView();
|
||||
this.ContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.insertRowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.deleteRowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.XMLStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.XMLView)).BeginInit();
|
||||
this.ContextMenu.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// XMLStrip
|
||||
|
|
@ -105,6 +110,29 @@
|
|||
this.XMLView.Name = "XMLView";
|
||||
this.XMLView.Size = new System.Drawing.Size(800, 426);
|
||||
this.XMLView.TabIndex = 30;
|
||||
this.XMLView.CellMouseUp += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.XMLView_CellMouseUp);
|
||||
//
|
||||
// ContextMenu
|
||||
//
|
||||
this.ContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.insertRowToolStripMenuItem,
|
||||
this.deleteRowToolStripMenuItem});
|
||||
this.ContextMenu.Name = "contextMenuStrip1";
|
||||
this.ContextMenu.Size = new System.Drawing.Size(134, 48);
|
||||
//
|
||||
// insertRowToolStripMenuItem
|
||||
//
|
||||
this.insertRowToolStripMenuItem.Name = "insertRowToolStripMenuItem";
|
||||
this.insertRowToolStripMenuItem.Size = new System.Drawing.Size(133, 22);
|
||||
this.insertRowToolStripMenuItem.Text = "Insert Row";
|
||||
this.insertRowToolStripMenuItem.Click += new System.EventHandler(this.insertRowToolStripMenuItem_Click);
|
||||
//
|
||||
// deleteRowToolStripMenuItem
|
||||
//
|
||||
this.deleteRowToolStripMenuItem.Name = "deleteRowToolStripMenuItem";
|
||||
this.deleteRowToolStripMenuItem.Size = new System.Drawing.Size(133, 22);
|
||||
this.deleteRowToolStripMenuItem.Text = "Delete Row";
|
||||
this.deleteRowToolStripMenuItem.Click += new System.EventHandler(this.deleteRowToolStripMenuItem_Click);
|
||||
//
|
||||
// XMLContentEditor
|
||||
//
|
||||
|
|
@ -121,6 +149,7 @@
|
|||
this.XMLStrip.ResumeLayout(false);
|
||||
this.XMLStrip.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.XMLView)).EndInit();
|
||||
this.ContextMenu.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
|
|
@ -134,4 +163,7 @@
|
|||
private System.Windows.Forms.ToolStripMenuItem partColorsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
|
||||
private System.Windows.Forms.DataGridView XMLView;
|
||||
private System.Windows.Forms.ContextMenuStrip ContextMenu;
|
||||
private System.Windows.Forms.ToolStripMenuItem insertRowToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem deleteRowToolStripMenuItem;
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ public partial class XMLContentEditor : Form
|
|||
public Provider[] contentProviders;
|
||||
List<object> loaderList = new List<object>();
|
||||
XMLContentType ListType;
|
||||
BindingSource XMLDataBinding;
|
||||
private int rowIndex = 0;
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
|
@ -47,6 +47,16 @@ public partial class XMLContentEditor : Form
|
|||
|
||||
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
//https://stackoverflow.com/questions/37145086/datagridview-remove-empty-rows-button
|
||||
for (int i = XMLView.Rows.Count - 1; i > -1; i--)
|
||||
{
|
||||
DataGridViewRow row = XMLView.Rows[i];
|
||||
if (!row.IsNewRow && row.Cells[0].Value == null)
|
||||
{
|
||||
XMLView.Rows.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
List<Provider> providerList = new List<Provider>();
|
||||
List<PartColor> partColorList = new List<PartColor>();
|
||||
|
||||
|
|
@ -54,15 +64,6 @@ public partial class XMLContentEditor : Form
|
|||
{
|
||||
if (data.IsNewRow) continue;
|
||||
|
||||
//https://stackoverflow.com/questions/8255186/how-to-check-empty-and-null-cells-in-datagridview-using-c-sharp
|
||||
for (int i = 0; i < data.Cells.Count; i++)
|
||||
{
|
||||
if (data.Cells[i].Value == null || data.Cells[i].Value == DBNull.Value || string.IsNullOrWhiteSpace(data.Cells[i].Value.ToString()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
switch (ListType)
|
||||
{
|
||||
case XMLContentType.ContentProviders:
|
||||
|
|
@ -142,6 +143,34 @@ public partial class XMLContentEditor : Form
|
|||
MessageBox.Show(fileName + " has been saved! The list will now reload.", "XML Content Editor - File Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
LoadXML(ListType);
|
||||
}
|
||||
|
||||
//http://csharp.net-informations.com/datagridview/deletegridview.htm
|
||||
private void XMLView_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
XMLView.Rows[e.RowIndex].Selected = true;
|
||||
rowIndex = e.RowIndex;
|
||||
XMLView.CurrentCell = XMLView.Rows[e.RowIndex].Cells[1];
|
||||
ContextMenu.Show(Cursor.Position);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteRowToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!XMLView.Rows[rowIndex].IsNewRow)
|
||||
{
|
||||
XMLView.Rows.RemoveAt(rowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void insertRowToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!XMLView.Rows[rowIndex].IsNewRow)
|
||||
{
|
||||
XMLView.Rows.Insert(rowIndex, 1);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Functions
|
||||
|
|
@ -230,4 +259,5 @@ public partial class XMLContentEditor : Form
|
|||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
|
|
@ -120,6 +120,9 @@
|
|||
<metadata name="XMLStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="ContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>118, 17</value>
|
||||
</metadata>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
|
|
|
|||
Loading…
Reference in New Issue