I'm working on a school assignment where I import data into a DataGridView in WinForm from a CSV file. This all works perfect, however, now I want to assign a value to a button (In column 5, 6 and 8) These can all vary depending on what the value in the same row, in column 3 is. If the value from column 3 is "Input" on the same row, in column 5, the button needs to be "Input", the rest of the cells in that row after column 5 need to be readonly textboxes.
If the value from column 3 is "Output" on the same row, in column 5, the button needs to be "On", in column 6 it needs to be "Off" and in column 8 it needs to be "On #s"
I've tried:
Looping through all the cells, foreach loops, looping through column 3, but I'm not sure how I can change the value of button in the same row. (They also need to have a different function when you click them, but I think that is easier when I understand how this works)
Here is a preview of the CSV file that needs to be used.
This is the code I've written so far (thats working):
private void btnBevestig_Click(object sender, EventArgs e)
{
try
{
LaadCSVToDataGrid(openFile.FileName);
dataGridView1.Sort(dataGridView1.Columns[3], ListSortDirection.Ascending);
dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[1].ReadOnly = true;
dataGridView1.Columns[1].Width = 250;
dataGridView1.Columns[2].Visible = false;
dataGridView1.Columns[3].ReadOnly = true;
dataGridView1.Columns[4].Visible = false;
DataGridViewButtonColumn btnInput = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btnInput);
btnInput.HeaderText = "Functie";
btnInput.Text = "";
btnInput.Name = "colInput";
btnInput.UseColumnTextForButtonValue = true;
DataGridViewButtonColumn btnOff = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btnOff);
btnOff.HeaderText = "";
btnOff.Text = "";
btnOff.Name = "colInput";
btnOff.UseColumnTextForButtonValue = true;
DataGridViewTextBoxColumn txtAantalSeconden = new DataGridViewTextBoxColumn();
dataGridView1.Columns.Add(txtAantalSeconden);
txtAantalSeconden.HeaderText = "";
txtAantalSeconden.Name = "txtAantalSec";
txtAantalSeconden.ReadOnly = false;
DataGridViewButtonColumn btnOnSec = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btnOnSec);
btnOnSec.HeaderText = "";
btnOnSec.Text = "";
btnOnSec.Name = "colInput";
btnOnSec.UseColumnTextForButtonValue = true;
btnOntgrendel.Enabled = true;
comboBoxProfiel.Enabled = false;
btnBevestig.Enabled = false;
btnKiesProfiel.Enabled = false;
btnNieuwProfiel.Enabled = false;
}
catch (Exception error)
{
MessageBox.Show(
error.Message,
"Fout",
MessageBoxButtons.OK,
MessageBoxIcon.Warning
);
}
}
What I have tried:
I've tried doing loops, everything worked fine up until the point that I have to edit the button's text.