I have 1 datagridview, 5 comboboxes, and 2 checkboxes. The comboboxes and checkboxes are separate from the datagridview; think datagridview with some options off the side of it. It is a 17x4 datagridview and it needs to stay that size. I have got them all saved to the same text file in the order and format that I need. Now I am trying to open the text file to those things specified above.
I got the datagridview information from the text file displayed correctly, that's if I leave the comboboxes and checkboxes out of the text file. When I add the comboboxes and checkboxes they just tack on some new rows to my datagridview.
Here is my open dialog code. I'm thinking I need to specify the sections then tell what line needs to go where, but that is where I get lost.
private void labelLoad_Click(object sender, EventArgs e)
{
filldata(); //datagridview constructor
dataGridView1.AutoGenerateColumns = false;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
System.IO.StreamReader file = new System.IO.StreamReader(openFileDialog1.FileName);
string[] columnnames = file.ReadLine().Split(',');
DataTable dt = new DataTable();
foreach (string c in columnnames)
{
dt.Columns.Add(c);
}
string newline;
while ((newline = file.ReadLine()) != null)
{
DataRow dr = dt.NewRow();
string[] values = newline.Split(',');
for (int i = 0; i < values.Length; i++)
{
dr[i] = values[i];
}
dt.Rows.Add(dr);
}
dataGridView1.DataSource = dt;
//string comboLoadTimeOutTime = file.ReadLine();
//string comboLoadPreAlert = file.ReadLine();
//string comboLoadSquelch = file.ReadLine();
//string comboLoadMic = file.ReadLine();
//string comboLoadVoice = file.ReadLine();
//string checkLoadBattery = file.ReadLine();
//string checkLoadBeep = file.ReadLine();
file.Close();
panelCreateRadioSettings.Visible = true;
panelSources.Visible = false;
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
dataGridView1.Columns[i].DataPropertyName = dt.Columns[i].ColumnName;
}
}
else
{
return;
}
}
my text file is like this:
name, name, name, name
1,,,
2,,,
(all the way to...)
16,,,
120 (`comboboxes` start here)
off
4
high
normal
1 (`checkboxes` start here)
1
Aucun commentaire:
Enregistrer un commentaire