Untitled
unknown
plain_text
2 years ago
3.4 kB
6
Indexable
using System;
using System.Windows.Forms;
namespace lab4
{
public partial class Form1 : Form
{
public int N = 0; // Describe quantity of columns
public int M = 0; // Describe quantity of rows
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "3";
textBox2.Text = "2";
button1_Click(sender, e);
}
private void button1_Click(object sender, EventArgs e)
{
N = Convert.ToInt32(textBox1.Text);
M = Convert.ToInt32(textBox2.Text);
int numberOfColumns = M; // Specify the desired number of columns
dataGridView1.Columns.Clear(); // Clear any existing columns
dataGridView2.Rows.Clear(); // Clear any existing rows in dataGridView2
for (int i = 0; i < numberOfColumns; i++)
{
string columnName = "Column " + (i + 1); // Generate column name
dataGridView1.Columns.Add(columnName, columnName); // Add column to the DataGridView
}
int numberOfRows = N; // Specify the desired number of rows
Random rnd = new Random();
for (int i = 0; i < numberOfRows; i++)
{
DataGridViewRow row = new DataGridViewRow();
for (int j = 0; j < numberOfColumns; j++)
{
//string cellValue = "Row " + (i + 1) + ", Column " + (j + 1); // Generate cell value
DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
//cell.Value = cellValue; // Set the cell value
row.Cells.Add(cell); // Add the cell to the row
row.Cells[j].Value = rnd.Next(0, 34);
}
dataGridView1.Rows.Add(row); // Add the row to the DataGridView
dataGridView1.Rows[i].HeaderCell.Value = i.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
dataGridView2.Rows.Clear(); // Clear any existing rows in dataGridView2
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
DataGridViewRow row = dataGridView1.Rows[i];
bool isDescending = true;
for (int j = 0; j < row.Cells.Count - 1; j++)
{
int currentCellValue = Convert.ToInt32(row.Cells[j].Value);
int nextCellValue = Convert.ToInt32(row.Cells[j + 1].Value);
if (currentCellValue <= nextCellValue)
{
isDescending = false;
break;
}
}
if (i + 1 <= dataGridView1.Rows.Count)
{
dataGridView2.Rows.Add(isDescending ? "1" : "0");
}
}
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show($"Column: {e.ColumnIndex}\nRow: {e.RowIndex}\nValue: {dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value}");
}
}
}Editor is loading...