diff --git a/Form1.Designer.cs b/Form1.Designer.cs index c9db810..90dcf32 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -41,6 +41,8 @@ private void InitializeComponent() this.openFileDialog2 = new System.Windows.Forms.OpenFileDialog(); this.button6 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); + this.button7 = new System.Windows.Forms.Button(); + this.button8 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // @@ -149,12 +151,34 @@ private void InitializeComponent() this.label1.Text = "Select your m3u8 file"; this.label1.Click += new System.EventHandler(this.label1_Click); // + // button7 + // + this.button7.Location = new System.Drawing.Point(333, 426); + this.button7.Name = "button7"; + this.button7.Size = new System.Drawing.Size(39, 23); + this.button7.TabIndex = 9; + this.button7.Text = "Up"; + this.button7.UseVisualStyleBackColor = true; + this.button7.Click += new System.EventHandler(this.button7_Click); + // + // button8 + // + this.button8.Location = new System.Drawing.Point(378, 426); + this.button8.Name = "button8"; + this.button8.Size = new System.Drawing.Size(47, 23); + this.button8.TabIndex = 10; + this.button8.Text = "Down"; + this.button8.UseVisualStyleBackColor = true; + this.button8.Click += new System.EventHandler(this.button8_Click); + // // Form1 // this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 454); + this.Controls.Add(this.button8); + this.Controls.Add(this.button7); this.Controls.Add(this.label1); this.Controls.Add(this.button6); this.Controls.Add(this.button5); @@ -191,6 +215,8 @@ private void InitializeComponent() private System.Windows.Forms.OpenFileDialog openFileDialog2; private System.Windows.Forms.Button button6; private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button button7; + private System.Windows.Forms.Button button8; } } diff --git a/Form1.cs b/Form1.cs index d8bde4a..9371fee 100644 --- a/Form1.cs +++ b/Form1.cs @@ -299,5 +299,44 @@ private void label1_Click(object sender, EventArgs e) { } + + private void button7_Click(object sender, EventArgs e) + { + MoveSelectedRow(-1); //Moveup + } + + private void MoveSelectedRow(int direction) + { + // Exit if no cell is selected or multiple cells are selected + if (dataGridView1.SelectedCells.Count != 1) + { + MessageBox.Show("Please select a single cell to move its row."); + return; + } + + // Get the selected cell + DataGridViewCell selectedCell = dataGridView1.SelectedCells[0]; + int rowIndex = selectedCell.RowIndex; + int newRowIndex = rowIndex + direction; + + // Exit if the new row index is out of bounds + if (newRowIndex < 0 || newRowIndex >= dataGridView1.Rows.Count) + { + return; + } + + // Swap the rows + DataGridViewRow selectedRow = dataGridView1.Rows[rowIndex]; + dataGridView1.Rows.Remove(selectedRow); + dataGridView1.Rows.Insert(newRowIndex, selectedRow); + + // Reselect the moved cell + dataGridView1.ClearSelection(); + dataGridView1.Rows[newRowIndex].Cells[selectedCell.ColumnIndex].Selected = true; + } + private void button8_Click(object sender, EventArgs e) + { + MoveSelectedRow(1); //Move down + } } }