Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am completely stumped.

 

I have a datagrid that is acting very strangely. The following method handles the ColumnChanging event of the underlying table:

 

   Private Sub tbl_ColumnChanging(ByVal sender As Object, _
        ByVal e As System.Data.DataColumnChangeEventArgs) Handles _
        tbl.ColumnChanging

       If Not IsNumeric(e.ProposedValue) Then
           e.Row.SetColumnError(e.Column, "You must enter a number")
           Exit Sub
       End If
       If AlreadyChecked(dgrData.CurrentCell.RowNumber, dgrData.CurrentCell.ColumnNumber) Then
           Exit Sub
       End If
       AlreadyChecked(dgrData.CurrentCell.RowNumber, dgrData.CurrentCell.ColumnNumber) = True
       Dim LastPoint As Int16

       ' The TreadData class simply returns an OLEDBDataReader
       ' when I pass it an SQL statement. It works fine throughout
       ' the rest of my program.
       Dim tdMaxPoints As TreadData = New TreadData("SELECT MAX(Point_ID) AS MaxPointID " & _
           "FROM Points INNER JOIN " & _
           "(Grooves INNER JOIN (Tires INNER JOIN Tests ON Tires.Test_ID = " & _
           "Tests.Test_ID) ON Grooves.Tire_ID = Tires.Tire_ID) ON Points.Groove_ID " & _
           "= Grooves.Groove_ID WHERE GrooveNumber = " & dgrData.CurrentCell.RowNumber - 1 & " AND " & _
           "PointNumber = " & dgrData.CurrentCell.ColumnNumber)
       While tdMaxPoints.TreadReader.Read
           Dim tdPoints As TreadData = New TreadData("SELECT Measure FROM Points " & _
               "WHERE Point_ID = " & tdMaxPoints.TreadReader("MaxPointID"))

           ' Right after the previous line, before the next line, my code
           ' jumps back to the beginning of this method.

           While tdPoints.TreadReader.Read
                'Do Stuff
           End While
   End Sub

 

At the point I indicated in the code, my app jumps back to the beginning of that method. Apparently, the underlying table changes in the middle of the ColumnChanging event?! When I check the proposedvalue on the second pass through, it shows an empty string instead of the value that had been entered.

 

The only thing I could think of was another thread changing something. I have one other thread running which is listening for input from the serial port. But, I tried disabling that thread, and I got the same behavior.

 

I also am experiencing strange behavior with the method that is handling the Enter event for all of the textboxes on my datagrid. I think this may be related. If I put an 'Exit Sub' at the beginning of the ColumnChanging event so as to bypass it, the TextBox_Enter method exhibits the following behavior: It will perform the method twice for each textbox. But, only if I have changed a value in the previous textbox. In other words, only when the ColumnChanging event occurs. If I tab to another textbox without changing the value, the Enter event only happens once.

 

   Private Sub dgrData_TextBox_Enter(ByVal sender As Object, ByVal e As _ EventArgs)
       If dgrData.CurrentCell.ColumnNumber = dsMeasures.Tables(0).Columns.Count - 2 And _
           dgrData.CurrentCell.RowNumber = dsMeasures.Tables(0).Rows.Count - 1 Then
           btnDone.Focus()
           Exit Sub
       ElseIf dgrData.CurrentCell.ColumnNumber = dsMeasures.Tables(0).Columns.Count - 2 Or _
           dgrData.CurrentCell.ColumnNumber = dsMeasures.Tables(0).Columns.Count - 1 Then
           Dim r As Int16 = dgrData.CurrentCell.RowNumber
           dgrData.CurrentCell = New DataGridCell(r + 1, 1)
       ElseIf dgrData.CurrentCell.ColumnNumber = 0 Then
           Dim r As Int16 = dgrData.CurrentCell.RowNumber
           dgrData.CurrentCell = New DataGridCell(r, 1)
       ElseIf dgrData.CurrentCell.RowNumber > NumGrooves - 1 Then
           dgrData.CurrentCell = New DataGridCell(dsMeasures.Tables(0).Rows.Count - 1, 1)
       End If
   End Sub

 

Any thoughts?

Posted

Damn dude... too many lines at this point for me to evaluate... sorry.

 

What I have to say to you is:

 

Your thread header: "Problem with DataGrid"

- No man... that's wrong... the Datagrid itself is a/the problem... throw it off for god sake... :D

Your first statement: "I am completely stumped."

Yeah ... you and a few more milions programmers that're still using datagrid...

 

:D I'm joking but... saying the truth...

 

As a helper for you it would worth a look at http://dotnet.leadit.be/extendeddatagrid/

This is a nice, free, DataGrid extension if you don't want to spend some money on something good... (I can't open it, don't know if it's only down or actually gonne! :( still I leave you my last download of it...)

 

Alex :p

Leadit.ExtendedDataGrid_0_1_2_2_for_1_0.zip

Software bugs are impossible to detect by anybody except the end user.
Posted

Thanks. I appreciate it. I will check this out.

 

I decided to use textboxes for my current problem instead of a datagrid because I have a fixed number of rows and columns. I was just hoping the datagrid would make things a little easier. I still haven't figured out why the column data would change in the middle of the ColumnChanging event handler.

 

Maybe the .NET 2.0 datagrid will be the cure for our ailments.

Posted

Hi again...

 

I still haven't figured out why the column data would change in the middle of the ColumnChanging event handler.

I don't know either since I don't use the datagrid, but when something like that occurs we can set a flag to protect howr evet code.

This means that you can create a boolean var that states if the code is to be runned or not... something like:

 

dim flag as boolean = true 'True = Run code / False = Don't Run Code

...

Private sub myEvent...

If flag then

flag = false

 

'*** your code ***

 

flag = true

end if

End Sub

 

This way, even if the same event is called while it's running it doesn't repeat the same code...

 

This isn't even a bad practice... it's something worst but... what a heck! :)

 

Alex :p

Software bugs are impossible to detect by anybody except the end user.
Posted
What does your alreadychecked function do?

 

AlreadyChecked is just an array of Boolean values that indicates whether a particular cell has already been validated. It does not change or even access any table data.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...