rmmarsh
asked on
How to access cell in DataGridView using a Switch statement
I have the following code... currently I am using a switch statement which looks for the content of one of the cells in the DGV... I want to change the switch statement to look for the row number of the DGV, (i.e. the case statement would be "case 0:, case 1:, etc)... I can't see anyway to get the row number for the switch statement...
Help please?
Help please?
DataTable dt = new DataTable();
FbDataAdapter da = new FbDataAdapter("SELECT * from tUploadInfo", mainForm.bookConn);
da.Fill(dt); // fill datatable
if (dgv1.Rows.Count > 0)
try {
dgv1.Rows.Clear(); // clear the old crappola out...
}
catch (Exception) // can't clear the first time... donno why
{
;
}
dgv1.Columns.Clear();
dgv1.DataSource = dt;
dgv1.Columns[0].HeaderText = "Listing Service";
dgv1.Columns[0].MinimumWidth = 120;
dgv1.Columns[1].HeaderText = "User ID";
dgv1.Columns[1].MinimumWidth = 140;
dgv1.Columns[2].HeaderText = "Password";
dgv1.Columns[2].MinimumWidth = 80;
dgv1.Columns[3].HeaderText = "FTP Address";
dgv1.Columns[3].MinimumWidth = 160;
dgv1.Columns[4].HeaderText = "FTP Directory";
dgv1.Columns[4].MinimumWidth = 105;
dgv1.Columns[5].HeaderText = "File Format";
dgv1.Columns[5].MinimumWidth = 10;
foreach (DataGridViewRow dataRow in dgv1.Rows) {
if (dataRow.Cells[0].Value == null)
continue;
switch (dataRow.Cells[0].Value.ToString()) // move the data to internal strings <------------------------ TODO
{
case "A1 Books":
mainForm.A1BooksUID = dataRow.Cells[1].Value.ToString();
mainForm.A1BooksPwd = dataRow.Cells[2].Value.ToString();
break;
case "ABE":
mainForm.ABEUID = dataRow.Cells[1].Value.ToString();
mainForm.ABEPwd = dataRow.Cells[2].Value.ToString();
break;
case "Alibris":
mainForm.AlibrisUID = dataRow.Cells[1].Value.ToString();
mainForm.AlibrisPwd = dataRow.Cells[2].Value.ToString();
break;
ASKER
No, I need to have the row number/index as part of the Switch statement...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Looks like that might work... let me give it a go and I'll get back to you... thanks...
ASKER
Thank you...
Glad to help
Open in new window