Results 1 to 5 of 5

Thread: How to catch this exception? [2003]

Threaded View

  1. #1

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    How to catch this exception? [2003]

    Tricky one. I downloaded this project from MSDN, DownloadManagerRefactored. I needed it because I need to display ComboBoxes in a datagrid.

    Things are great except I am unable to edit my textboxes when the dataGrid is set to Readonly. So fine I set the dataGrid to ReadOnly = False, but then I get the new and blank record. This is what messes me up. If I click anywhere on the new record, I get an untrappable error (see pic).

    This is no good because even though I can kind of "hide" it, the user can still hit the [Enter] key while editing the last row and that sets focus on the last row and the same thing happens.

    I may be able to trap the columns under the Labal and/or ComboBox, but not the TextBox. I can upload the project but you won't be able to see it in action because it is database driven. I can post the main code that sets it up:

    VB Code:
    1. Private Sub BindControls()
    2.  
    3.             Dim strTestName As String
    4.             Dim strColumnName As String
    5.             Dim intColumntype As Integer
    6.             Dim i As Integer
    7.             Dim strCol As String
    8.             Dim strDropdownValue As String
    9.             Dim strSerialNumber As String
    10.  
    11.             Dim strCol1 As String
    12.             Dim strCol2 As String
    13.             Dim strCol3 As String
    14.  
    15.             MyConnection = New SqlConnection
    16.             MyConnection.ConnectionString = cmbxSQLConnectionString.Text
    17.             MyConnection.Open()
    18.  
    19.             MyCommand = New SqlCommand("spIASGetTest", MyConnection)
    20.             MyCommand.CommandType = CommandType.StoredProcedure
    21.             MyCommand.Parameters.Add("@testName", SqlDbType.VarChar).Value = cmbxLabTests.Text
    22.             MyDataReader = MyCommand.ExecuteReader()
    23.  
    24.             Dim dmTable As New DataTable
    25.  
    26.             If MyDataReader.HasRows Then
    27.                 '
    28.                 While (MyDataReader.Read())
    29.                     '
    30.                     strTestName = MyDataReader.Item("Test Name")
    31.                     strColumnName = MyDataReader.Item("columnName")
    32.                     '
    33.                     dmTable.Columns.Add(New DataColumn(strColumnName, GetType(String)))
    34.                     '
    35.                 End While
    36.                 '
    37.             End If
    38.             '
    39.             MyDataReader.Close()
    40.  
    41.             Dim dst As New DataGridTableStyle
    42.  
    43.             dmTable.TableName = strTestName
    44.             dst.MappingName = strTestName
    45.  
    46.             ' Sample No
    47.             strCol1 = dmTable.Columns.Item(0).ToString
    48.             Dim dglcSampleNo As New DataGridLabelColumn
    49.             dglcSampleNo.MappingName = strCol1
    50.             dglcSampleNo.HeaderText = strCol1
    51.             dst.GridColumnStyles.Add(dglcSampleNo)
    52.             '
    53.             '
    54.             Dim dgcbc As DataGridComboBoxColumn
    55.             Dim dgtbc As DataGridTextBoxColumn
    56.  
    57.             For i = 1 To dmTable.Columns.Count - 1
    58.                 '
    59.                 strCol = dmTable.Columns.Item(i).ToString
    60.                 '
    61.                 MyCommand = New SqlCommand("spIASGetDropDown", MyConnection)
    62.                 MyCommand.CommandType = CommandType.StoredProcedure
    63.                 MyCommand.Parameters.Add("@testName", SqlDbType.VarChar).Value = strTestName
    64.                 MyCommand.Parameters.Add("@columnName", SqlDbType.VarChar).Value = strCol
    65.                 '
    66.                 MyDataReader = MyCommand.ExecuteReader()
    67.                 '
    68.                 If MyDataReader.HasRows Then
    69.                     '
    70.                     dgcbc = New DataGridComboBoxColumn
    71.                     dgcbc.MappingName = strCol
    72.                     dgcbc.HeaderText = strCol
    73.                     '
    74.                     dgcbc.Add("")
    75.                     '
    76.                     While (MyDataReader.Read())
    77.                         strDropdownValue = MyDataReader.Item("dropDownString")
    78.                         dgcbc.Add(strDropdownValue)
    79.                     End While
    80.                     '
    81.                     dst.GridColumnStyles.Add(dgcbc)
    82.                     '
    83.                 Else
    84.                     dgtbc = New DataGridTextBoxColumn
    85.                     dgtbc.MappingName = strCol
    86.                     dgtbc.HeaderText = strCol
    87.                     dst.GridColumnStyles.Add(dgtbc)
    88.                End If
    89.                 '
    90.                 MyDataReader.Close()
    91.                 '
    92.             Next
    93.  
    94.             MyCommand = New SqlCommand("spIASGetSerialNumbers", MyConnection)
    95.             MyCommand.CommandType = CommandType.StoredProcedure
    96.             MyCommand.Parameters.Add("@projectName", SqlDbType.VarChar).Value = Me.txtProject.Text
    97.             MyDataReader = MyCommand.ExecuteReader()
    98.  
    99.             Dim dr As DataRow
    100.  
    101.             If MyDataReader.HasRows Then
    102.                 '
    103.                 While (MyDataReader.Read())
    104.                     '
    105.                     strSerialNumber = MyDataReader.Item("serialNumber")
    106.                     '
    107.                     dr = dmTable.NewRow()
    108.                     '
    109.                     strCol1 = dmTable.Columns.Item(0).ToString
    110.                     dr(strCol1) = strSerialNumber
    111.                     '
    112.                     For i = 1 To dmTable.Columns.Count - 1
    113.                         strCol = dmTable.Columns.Item(i).ToString
    114.                         dr(strCol) = "0"
    115.                     Next
    116.                     '
    117.                     dmTable.Rows.Add(dr)
    118.                     '
    119.                 End While
    120.                 '
    121.             End If
    122.  
    123.             dataGrid.TableStyles.Add(dst)
    124.             dataGrid.DataSource = dmTable
    125.             dataGrid.ReadOnly = False
    126.  
    127.         End Sub
    Attached Images Attached Images  
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width