Click here to Skip to main content
16,021,823 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have a data grid view in a form, where I have done some work such as getting specific cell value and some other validation in DataGridView.RowEnter event. This event is fired twice while the form is loading. After that, each time a Row is selected with Left Mouse Button, this event fires.

But I have done some code in the MouseDown event to select the row when I click Right Mouse Button. But the problem is this time RowEnter event doesn't fire and I can't get the specific cell value of the selected row. It just returns the previous values it has.

this is code block of RowEnter event.

C#
private void dgvNewTestRequests_RowEnter(object sender, DataGridViewCellEventArgs e)
        {

            String testStatus = "";
            String test = "";
            //String patientName = "";
            ResetAll();
            patientID = Convert.ToInt32(dgvNewTestRequests.Rows[e.RowIndex].Cells[0].Value.ToString());
            patientName = dgvNewTestRequests.Rows[e.RowIndex].Cells[1].Value.ToString();
            testStatus = dgvNewTestRequests.Rows[e.RowIndex].Cells[8].Value.ToString();

            if (testStatus == "Incomplete")
            {
                markAsCompletedToolStripMenuItem.Enabled = true;
                markAsIncompleteToolStripMenuItem.Enabled = false;
                //ChangeRowColor();
            }
            else
            {
                markAsCompletedToolStripMenuItem.Enabled = false;
                markAsIncompleteToolStripMenuItem.Enabled = true;
                //ChangeRowColor();
            }

            for (int i = 4; i <= 7; i++)
            {
                test = dgvNewTestRequests.Rows[e.RowIndex].Cells[i].Value.ToString();
                if (test == "Blood Test")
                    bloodTestInventoryToolStripMenuItem.Enabled = true;

                if (test == "Urine Test")
                    urineTestInventoryToolStripMenuItem.Enabled = true;
                if (test == "X-Ray")
                    xRayInventoryToolStripMenuItem.Enabled = true;
                if (test == "Ultrasonography")
                    ultrasonographyInventoryToolStripMenuItem.Enabled = true;
            }
        }

I want to do the same thing when i right clicked the mouse button to select the row.
Posted

1 solution

try :
C#
dgvNewTestRequests["column index here",dgvNewTestRequestsSelectedRows[0].Index] 

or try :
C#
int Row_index=dgvNewTestRequests.SelectedCells[0].RowIndex;
int Column_index=dgvNewTestRequests.SelectedCells[0].ColumnIndex

dgvNewTestRequests[Column_index,Row_index]
 
Share this answer
 
v2
Comments
Jyoti Choudhury 8-Oct-11 2:35am    
Thanks a lot. It solved my problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900