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?
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;

Open in new window

rmmarshAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carlos VillegasFull Stack .NET DeveloperCommented:
Row number/index? like this?
            int myRowIndex = -1;
            foreach (DataGridViewRow dataRow in dgv1.Rows) {
                myRowIndex++;

                if (dataRow.Cells[0].Value == null)
                    continue;


                // etc............
            }

Open in new window

rmmarshAuthor Commented:
No, I need to have the row number/index as part of the Switch statement...
Carlos VillegasFull Stack .NET DeveloperCommented:
OK, like this?
int myRowIndex = -1;
foreach (DataGridViewRow dataRow in dgv1.Rows) {
	myRowIndex++;

	if (dataRow.Cells[0].Value == null)
	    continue;

	switch (myRowIndex)
	{
	    case 0:
		mainForm.A1BooksUID = dataRow.Cells[1].Value.ToString();
		mainForm.A1BooksPwd = dataRow.Cells[2].Value.ToString();
		break;
	    case 1:
		mainForm.ABEUID = dataRow.Cells[1].Value.ToString();
		mainForm.ABEPwd = dataRow.Cells[2].Value.ToString();
		break;

// etc............

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

rmmarshAuthor Commented:
Looks like that might work... let me give it a go and I'll get back to you... thanks...
rmmarshAuthor Commented:
Thank you...
Carlos VillegasFull Stack .NET DeveloperCommented:
Glad to help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.