To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > .NET > ASP.NET

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Apr 13th, 2005, 11:32 AM   #1
Kelleyj75
New Member
 
Join Date: Apr 05
Location: Wisconsin
Posts: 4
Kelleyj75 is an unknown quantity at this point (<10)
Question refresh datagrid causes error if oper scrolls off to the right of grid

I have a datagrid that is populated with data. If the operator scrolls off to the click on a field that is off to the right (not initially displayed on the grid) ---- then the operator does something that needs to repopulate that data with a different set of information --- an error is generated. The new data consists of the same fields, but just it is just pulling in a different set of data. If the operator does not scroll off to the side of the grid but refreshes the grid with new information, the error does not occur. If the operator scrolls off to the right, but does not click on a cell, an error does not occur. I have included the code that binds data to the grid and displays it. I've narrowed down that it is stopping on the "dgtabhistory.DataSource = mydataview " statement where I bind the data to the view. The error says: "An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Column 'Strategy ID and Desc' does not belong to table ACTIVITYHISTORYGRID." The column name may change --- it kind of depends on how far over to the right I scroll on the grid and which cell I click on.

Does anyone know about a possible bug with VB.net? Or am I missing something?? Is there a special command(s) I need to do before I bind new data to a datagrid?




PHP Code:
Dim sqlConn4 As SqlConnection = New SqlConnection(Connection)

            
Try

                sqlConn4
.Open()
                
Dim sqlcomm4 As New SqlDataAdapter("salesRaptor_GetActivityHistoryPC", sqlConn4)
                
sqlcomm4.SelectCommand.CommandType = CommandType.StoredProcedure

                Dim workParam4
As SqlParameter = New SqlParameter
                workParam4
= sqlcomm4.SelectCommand.Parameters.Add("@Rep", SqlDbType.VarChar, 25)
                If
chkTabHistoryWholeTeam.CheckState = CheckState.Checked Then
                    sqlcomm4
.SelectCommand.Parameters("@Rep").Value = Rep_ID
                
Else
                    
sqlcomm4.SelectCommand.Parameters("@Rep").Value = txTabHistoryRepID.Text
                End
If
                
workParam4.Direction = ParameterDirection.Input

                workParam4
= sqlcomm4.SelectCommand.Parameters.Add("@Status", SqlDbType.VarChar, 25)
                
Dim type As String
                type
= ""
                
If cmbTabHistoryStatus.SelectedItem = "All Closed Statuses" Then type = ""
                
If cmbTabHistoryStatus.SelectedItem = "Emailed Status Only" Then type = "E"
                
If cmbTabHistoryStatus.SelectedItem = "Attempted Status Only" Then type = "A"
                
If cmbTabHistoryStatus.SelectedItem = "Completed Status Only" Then type = "C"
                
sqlcomm4.SelectCommand.Parameters("@Status").Value = type.ToString
                workParam4
.Direction = ParameterDirection.Input

                workParam4
= sqlcomm4.SelectCommand.Parameters.Add("@ProspectID", SqlDbType.VarChar, 25)
                
sqlcomm4.SelectCommand.Parameters("@ProspectID").Value = Prospid.ToString
                workParam4
.Direction = ParameterDirection.Input

                workParam4
= sqlcomm4.SelectCommand.Parameters.Add("@contactID", SqlDbType.VarChar, 25)
                If
tabhistproscontsw = "CONTACT" Then
                    sqlcomm4
.SelectCommand.Parameters("@contactid").Value = ActContid.ToString
                
Else
                    
sqlcomm4.SelectCommand.Parameters("@contactid").Value = ""
                
End If
                
workParam4.Direction = ParameterDirection.Input

                workParam4
= sqlcomm4.SelectCommand.Parameters.Add("@wholeteam", SqlDbType.VarChar, 1)
                If
chkTabHistoryWholeTeam.Checked = True Then
                    sqlcomm4
.SelectCommand.Parameters("@wholeteam").Value = "Y"
                
Else
                    
sqlcomm4.SelectCommand.Parameters("@wholeteam").Value = "N"
                
End If
                
workParam4.Direction = ParameterDirection.Input

                workParam4
= sqlcomm4.SelectCommand.Parameters.Add("@allreps", SqlDbType.VarChar, 1)
                If
chkTabHistoryAllReps.CheckState = CheckState.Checked Then
                    sqlcomm4
.SelectCommand.Parameters("@allreps").Value = "Y"
                
Else
                    
sqlcomm4.SelectCommand.Parameters("@allreps").Value = "N"
                
End If
                
workParam4.Direction = ParameterDirection.Input

                Dim ds
As New DataSet
                sqlcomm4
.Fill(ds, "ACTIVITYHISTORYGRID")     'holds data from query

                '
ds.Tables(0).Columns(16).ColumnMapping = MappingType.Hidden ' hide the record status field

                Dim x = ds.Tables(0).Rows.Count()
                Dim mydatatable As DataTable = ds.Tables(0) '
table name
                Dim mydataview
As DataView = mydatatable.DefaultView
                
' mydataview.Sort = "Date Closed"  'sort table
                dgtabhistory
.DataSource = mydataview 'binds data to grid

                Dim ts1 As New DataGridTableStyle '
change column widths
                ts1
.MappingName = "ACTIVITYHISTORYGRID"

                
Dim numRows As Integer = dgtabhistory.BindingContext(dgtabhistory.DataSource, dgtabhistory.DataMember).Count
                txRecCountHistory
.Text = "Count: " + CStr(numRows.ToString)
                If (
dgtabhistory.CurrentRowIndex < numRows) And (dgtabhistory.CurrentRowIndex > -1) Then
                    ContactHistoryActivityID
= CStr(dgtabhistory(dgtabhistory.CurrentRowIndex, 13).ToString) 'store current activity id
                End If

                Try             '
put inside a try because 2nd time through, it errors out
                    dgtabhistory
.TableStyles.Add(ts1)

                    
ts1.GridColumnStyles(0).Width = 120 ' change width of date/time fld
                    ts1.GridColumnStyles(1).Width = 150 '
change width of contact name
                    ts1
.GridColumnStyles(2).Width = 120 ' change width of status
                    ts1.GridColumnStyles(3).Width = 120 '
change width of type
                    ts1
.GridColumnStyles(4).Width = 200 ' change width of regarding
                    ts1.GridColumnStyles(5).Width = 200 '
change width of results
                    ts1
.GridColumnStyles(6).Width = 50 ' change width of priority
                    ts1.GridColumnStyles(7).Width = 100 '
change width of rep
                    ts1
.GridColumnStyles(8).Width = 100 ' change width of personal business
                    ts1.GridColumnStyles(9).Width = 150 '
change width of strategy id/des
                    ts1
.GridColumnStyles(10).Width = 90 ' change width of strategy level
                    ts1.GridColumnStyles(11).Width = 75 '
change width of order id
                    ts1
.GridColumnStyles(12).Width = 75 ' change width of prospect id
                    ts1.GridColumnStyles(13).Width = 75 '
change width of activity id
                    ts1
.GridColumnStyles(14).Width = 75 ' change width of contact id
                    ts1.GridColumnStyles(15).Width = 150 '
change width of name
                    ts1
.GridColumnStyles(16).Width = 75 ' change width of new prospect

                    ts1.DataGrid.Refresh()

                    '
date datetime fields to show time    
                    Dim dgtbc
As DataGridTextBoxColumn
                    dgtbc
= CType(dgtabhistory.TableStyles(0).GridColumnStyles(0), DataGridTextBoxColumn)
                    If
Not dgtbc Is Nothing Then dgtbc.Format = "g"


                
Catch

                End Try

                sqlConn4
.Close()

            
Catch tt As Exception
                Errmsg
= tt.ToString
                EventSW
= "Y"
                
errormsg() ' display error msg

                sqlConn4.Close()

            Finally
                sqlConn4.Close()

            End Try
Kelleyj75 is offline   Reply With Quote
Old Apr 16th, 2005, 03:04 PM   #2
Kelleyj75
New Member
 
Join Date: Apr 05
Location: Wisconsin
Posts: 4
Kelleyj75 is an unknown quantity at this point (<10)
Re: refresh datagrid causes error if oper scrolls off to the right of grid

I found the problem. I had to add dgtabhistory.DataSource = nothing before the dgtabhistory.DataSource = mydataview.
Kelleyj75 is offline   Reply With Quote
Reply

Go Back   VBForums > .NET > ASP.NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:52 PM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.