Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DataGridView not reflecting current row in RowStateChanged Event

Posted on 2014-10-18
3
Medium Priority
?
454 Views
Last Modified: 2014-10-20
I have a DataGridView that utilizes the RowStateChanged Event. I basically have textboxes that are associated with cells in the DGV. So, when the user uses the arrow key in the DGV depending on what row the cursor is on, that row's data will be reflected in the TextBoxes. For example, for a specific record, there are 4 rows that populate the DGV. In the RowStateChanged Event, I have code that will assign a specific Cell to a TextBox. After the DGV is loaded, I set the CurrentCell to the 1st Cell, 1st Row, however, the TextBoxes reflect data from the last row of data, in this case 4 or 3 if you go by zero index. I ran it thru the debugger and the RowStateChanged Event actually fires first before I set the CurrentCell position.

So, my question is how or where do I set the CurrentCell so the RowStateChanged Event will recognize it's new position?

Thanks,

Here is my code below.

    Private Sub dgvEquipmentItems_RowStateChanged(sender As Object, e As DataGridViewRowStateChangedEventArgs) Handles dgvEquipmentItems.RowStateChanged
        Try
            If blnIsLoaded Then
                txtSeqNO.Text = CStr(BL.CheckForNULLs(e.Row.Cells(1).Value))
                txtManufacturer.Text = CStr(BL.CheckForNULLs(e.Row.Cells(3).Value))
                txtComponentSerialNO.Text = CStr(BL.CheckForNULLs(e.Row.Cells(4).Value))
                txtItemNO.Text = CStr(BL.CheckForNULLs(e.Row.Cells(5).Value))
                txtModelNO.Text = CStr(BL.CheckForNULLs(e.Row.Cells(6).Value))
                txtChannel.Text = CStr(BL.CheckForNULLs(e.Row.Cells(8).Value))
                txtCapacity.Text = CStr(BL.CheckForNULLs(e.Row.Cells(11).Value))
                txtCapacityUnit.Text = CStr(BL.CheckForNULLs(e.Row.Cells(13).Value))
                txtLowerRange.Text = CStr(BL.CheckForNULLs(e.Row.Cells(15).Value))
                txtUpperRange.Text = CStr(BL.CheckForNULLs(e.Row.Cells(16).Value))
                txtRangeUnit.Text = CStr(BL.CheckForNULLs(e.Row.Cells(18).Value))
            End If

        Catch ex As Exception
            EH.ErrorMessage = "dgvEquipmentItems_RowStateChanged() - " & ex.Message & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub
   '
   '
   '
    Private Sub LoadDetailGrid()
            InitializeErrorClass(EH)
            BL.GetDETAILSEquipmentRecord(iEquipment_ID, dbDETAILS_Equipment, EH)

            dgvEquipmentItems.DataSource = Nothing

            If EH.ErrorMessage = String.Empty Then
                If EH.DataSet.Tables(0).Rows.Count > 0 Then
                    rowCnt = EH.DataSet.Tables(0).Rows.Count
                    dgvEquipmentItems.DataSource = EH.DataSet.Tables(0)
                    dgvEquipmentItems.Columns(0).Visible = False
                    dgvEquipmentItems.Columns(2).Visible = False
                    dgvEquipmentItems.Columns(7).Visible = False
                    dgvEquipmentItems.Columns(9).Visible = False
                    dgvEquipmentItems.Columns(12).Visible = False
                    dgvEquipmentItems.Columns(13).Visible = False
                    dgvEquipmentItems.Columns(17).Visible = False
                    dgvEquipmentItems.Columns(18).Visible = False
                    dgvEquipmentItems.Columns(19).Visible = False
                    dgvEquipmentItems.Columns(20).Visible = False
                    dgvEquipmentItems.Columns(21).Visible = False
                    dgvEquipmentItems.Columns(22).Visible = False
                    dgvEquipmentItems.Columns(23).Visible = False
                    dgvEquipmentItems.Columns(24).Visible = False
                    dgvEquipmentItems.Columns(25).Visible = False
                    dgvEquipmentItems.Columns(26).Visible = False
                    dgvEquipmentItems.Columns(27).Visible = False
                    dgvEquipmentItems.Columns(28).Visible = False
                    dgvEquipmentItems.Columns(29).Visible = False
                    dgvEquipmentItems.CurrentCell = dgvEquipmentItems.Rows(0).Cells(1)
                End If
            End If
    End Sub

Open in new window

0
Comment
Question by:BlakeMcKenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 40389906
RowStateChanged occurs on many different situations. The fact that the row is selected is only one of those. So you are not using the right event for what you want to do if I understand correctly.

Try with RowEnter instead.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40391726
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40391970
James,

RowEnter did the trick!

Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question