private void open(object sender, EventArgs e)
{
// only works for opening the table
dataGridView1.Rows.Clear();
OpenFileDialog openDialog = new OpenFileDialog();
if (openDialog.ShowDialog() == DialogResult.OK)
{
fileLabel.Text = openDialog.FileName;
// Use File.ReadAllLines, it's easier
string[] lines = File.ReadAllLines(openDialog.FileName);
foreach (string line in lines)
{
var text = line.Split(',', '\n');
dataGridView1.Rows.Add(text);
}
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
dataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString();
}
}
}
这是我目前的开放和阅读代码。所以我也有编写代码(实际上我已经编写了一个文本文件),我想在表单的某处添加一些信息,但不是dataGridView1
现在在我以前的版本中,我添加了以下代码来读取文本文件的额外行。
int k = 0;
while (k < lines.Length)
{
for (int j = 0; j < twoDTextBox.GetLength(0); j++)
{
for (int i = 0; i < twoDTextBox.GetLength(1); i++)
{
statsBonus[j, i].Text = lines[k];
k++;
}
}
// these lines I would like to add to read in my new file
textBox1.Text = lines[k];
k++;
comboBox1.SelectedItem = lines[k];
k++;
checkBox1.Checked = Convert.ToBoolean(lines[k]);
k++;
}
在我以前使用文本框之前,但后来发现它不是真正高效和动态。
那么现在如何在读取DataGridView行后将底线添加到表单中?