For Loop in a datagrid: Windows vs Web. I am SOOOO lost!!!!!

I am writing a WINDOWS form with a datagrid where i need to run a loop and basically flag every item (containers to be shipped in this case).  Now, I've done this with a webform and have had no problems what so ever with it but when it comes to a Windows Form the controls are differnt i.e., namespaces I can't perform the same functions.  Here is the sample code from a web form and I was wondering if anyone had any idea how to approach this from a windows form   Any help would be greatly appreciated.  Thanks!

        'Insert Shipping Request Information into tblContainer - manifestDocument & shipingRequestID
        Dim myDataGridItem As DataGridItem
          Dim strContainerID As String

        lblStatus.Text = "<br>You selected the Following containers to be shipped:<br><br>"
        'Look at notes:  Put the update clause back in at lblStatus.Text to update those records as they cycle through the Loop
        For Each myDataGridItem In dgContainer.Items
                strContainerID = CType(myDataGridItem.FindControl("lblContainerID"), Label).Text

                With cmdUpdateContainer
                    .Parameters("@containerID").Value = strContainerID
                    .Parameters("@containerShippingRequest").Value = fldID.Text
                    .Parameters("@containerUpdateDate").Value = Today
                    .Parameters("@containerDateShip").Value = fldDate.Text
                    .Parameters("@storageType").Value = "PEN"
                    .Parameters("@wasteStream").Value = ddlWasteStream.SelectedItem.Text
                End With
                SqlConnection2.Open()
                cmdUpdateContainer.ExecuteNonQuery()
                SqlConnection2.Close()
               End If
        Next


Answer this question

For Loop in a datagrid: Windows vs Web. I am SOOOO lost!!!!!

  • Aner

    I'm going to go look at the MSDS help that you suggested but looking at your code, I'm having trouble with the columnIndex.  Also, that should just pull the Key, but what if I want to pull other columns   Sorry for the stupid question, I'm just new to this.

    Thanks

  • Tom Isaacson

    Hi,
    I have some code that loops through the items in a datagrid.  I'm assuming your datagrid is bound to a data source.  colIndex is the zero-based index of the datagrid's column that contains the container IDs.

    Dim i As Integer
    Dim num As Integer = Me.BindingContext(DataGrid1.DataSource).Count
    For i = 0 To num - 1
          strContainerID = DataGrid1.Item(i, colIndex).ToString
    Next

    MSDN has a bunch of intro info on the datagrid control (ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcon/html/vbconintroductiontothedatagridcontrol.htm)

    Hope this helps.

  • For Loop in a datagrid: Windows vs Web. I am SOOOO lost!!!!!