Updating Datagrid not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kpreston
    New Member
    • May 2007
    • 4

    Updating Datagrid not working

    Please help, i have to finish this assignment ASAP.
    the project is to create a solution with 3 text box for FactoryID, FactoryName and FactoryAddress. next is to create 2 Datagrid for Customer and Supplier.
    Splash screen also create for start up the program.
    i have created most of the program but could not figure it out how to get the relationsive to work between Factory, Customer and the supplier.
    please reply.
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #2
    Welcome to TheScripts! Please read Homework Guidelines and post back with a specific problem. Thanks!

    Comment

    • kpreston
      New Member
      • May 2007
      • 4

      #3
      Originally posted by SammyB
      Welcome to TheScripts! Please read Homework Guidelines and post back with a specific problem. Thanks!
      Thanks for the advice.
      I have created form with text box (FactoryID, FactoryName and Address etc.)
      and created 2 datagrid to display Customer info (FactoryID, CustomerID etc.) the second datagrid is Supplier (FactoryID, SupplierID etc.).
      i have finished all of the above, created all the necessary connection (OleDbConnectio n, OleDbDatasdapte r and Dataset) to the Main form.
      MMuMain also created to navigate (First, Previous, next etc,). however when i click on next or previous the text box for the factoryID, address and name change accordingly, but the datagrid does not change according to the factory text box. like i had mentioned in the previous i have problems of understanding of how to setup the relationsive/or code?.
      please advise.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by kpreston
        Thanks for the advice.
        I have created form with text box (FactoryID, FactoryName and Address etc.)
        and created 2 datagrid to display Customer info (FactoryID, CustomerID etc.) the second datagrid is Supplier (FactoryID, SupplierID etc.).
        i have finished all of the above, created all the necessary connection (OleDbConnectio n, OleDbDatasdapte r and Dataset) to the Main form.
        MMuMain also created to navigate (First, Previous, next etc,). however when i click on next or previous the text box for the factoryID, address and name change accordingly, but the datagrid does not change according to the factory text box. like i had mentioned in the previous i have problems of understanding of how to setup the relationsive/or code?.
        please advise.
        How have you tried changing the DataGrid?
        Could you post a snippet of your code relating to this functionality so that we have a better idea of what you're doing?

        Thanks

        -Frinny

        Comment

        • kpreston
          New Member
          • May 2007
          • 4

          #5
          Below is the code from Main. Please asvice.
          [code=vbnet]
          Private Sub frmMain_Load(By Val sender As Object, ByVal e As System.EventArg s) Handles MyBase.Load
          Dim printRecords As Integer
          Dim dgtsCustomer As New DataGridTableSt yle()
          Dim dgtsSupplier As New DataGridTableSt yle()
          Dim pbndTemp As Binding
          Dim dtCustomers As DataTable

          ODbDaFactory.Fi ll(DsFactory3)

          Call EditState(cblnN otEditing)

          dgtsCustomer.Al ternatingBackCo lor = Color.LightBlue
          dgtsCustomer.Gr idLineColor = Color.Silver
          dgtsCustomer.Gr idLineStyle = DataGridLineSty le.Solid
          dgtsCustomer.Se lectionForeColo r = Color.Blue
          dgtsCustomer.Se lectionBackColo r = Color.Silver
          dgtsCustomer.Ma ppingName = _
          DsFactory.tblCu stomer.TableNam e
          dgCustomer.Tabl eStyles.Add(dgt sCustomer)

          'Customer, Formt the datagrid columns.
          dgtsCustomer.Gr idColumnStyles( 0).HeaderText = "Factory ID"
          dgtsCustomer.Gr idColumnStyles( 0).Alignment = _
          HorizontalAlign ment.Center
          dgtsCustomer.Gr idColumnStyles( 1).HeaderText = "Customer ID"
          dgtsCustomer.Gr idColumnStyles( 1).Alignment = _
          HorizontalAlign ment.Center
          dgtsCustomer.Gr idColumnStyles( 2).HeaderText = "Name"
          dgtsCustomer.Gr idColumnStyles( 2).Alignment = _
          HorizontalAlign ment.Center
          dgtsCustomer.Gr idColumnStyles( 3).HeaderText = "Address"
          dgtsCustomer.Gr idColumnStyles( 3).Alignment = _
          HorizontalAlign ment.Center
          dgtsCustomer.Gr idColumnStyles( 4).HeaderText = "City"
          dgtsCustomer.Gr idColumnStyles( 4).Alignment = _
          HorizontalAlign ment.Center
          dgtsCustomer.Gr idColumnStyles( 5).HeaderText = "State"
          dgtsCustomer.Gr idColumnStyles( 5).Alignment = _
          HorizontalAlign ment.Center
          dgtsCustomer.Gr idColumnStyles( 6).HeaderText = "Zip Code"
          dgtsCustomer.Gr idColumnStyles( 6).Alignment = _
          HorizontalAlign ment.Center
          dgtsCustomer.Gr idColumnStyles( 7).HeaderText = "Credit Limit"
          dgtsCustomer.Gr idColumnStyles( 7).Alignment = _
          HorizontalAlign ment.Center
          dgtsCustomer.Gr idColumnStyles( 8).HeaderText = "Balance Due"
          dgtsCustomer.Gr idColumnStyles( 8).Alignment = _
          HorizontalAlign ment.Center

          'Supplier, Formt the datagrid columns
          dgtsSupplier.Al ternatingBackCo lor = Color.LightBlue
          dgtsSupplier.Gr idLineColor = Color.Silver
          dgtsSupplier.Gr idLineStyle = DataGridLineSty le.Solid
          dgtsSupplier.Se lectionForeColo r = Color.Blue
          dgtsSupplier.Se lectionBackColo r = Color.Silver
          dgtsSupplier.Ma ppingName = _
          DsFactory.tblSu pplier.TableNam e
          dgSupplier.Tabl eStyles.Add(dgt sSupplier)

          dgtsSupplier.Gr idColumnStyles( 0).HeaderText = "Factory ID"
          dgtsSupplier.Gr idColumnStyles( 0).Alignment = _
          HorizontalAlign ment.Center
          dgtsSupplier.Gr idColumnStyles( 1).HeaderText = "Supplier ID"
          dgtsSupplier.Gr idColumnStyles( 1).Alignment = _
          HorizontalAlign ment.Center
          dgtsSupplier.Gr idColumnStyles( 2).HeaderText = "Supplier Name"
          dgtsSupplier.Gr idColumnStyles( 2).Alignment = _
          HorizontalAlign ment.Center
          dgtsSupplier.Gr idColumnStyles( 3).HeaderText = "Address"
          dgtsSupplier.Gr idColumnStyles( 3).Alignment = _
          HorizontalAlign ment.Center
          dgtsSupplier.Gr idColumnStyles( 4).HeaderText = "City"
          dgtsSupplier.Gr idColumnStyles( 4).Alignment = _
          HorizontalAlign ment.Center
          dgtsSupplier.Gr idColumnStyles( 5).HeaderText = "State"
          dgtsSupplier.Gr idColumnStyles( 5).Alignment = _
          HorizontalAlign ment.Center
          dgtsSupplier.Gr idColumnStyles( 6).HeaderText = "Zip Code"
          dgtsSupplier.Gr idColumnStyles( 6).Alignment = _
          HorizontalAlign ment.Center
          dgtsSupplier.Gr idColumnStyles( 7).HeaderText = "Credit Limit"
          dgtsSupplier.Gr idColumnStyles( 7).Alignment = _
          HorizontalAlign ment.Center



          End Sub



          Private Sub dgCustomer_Curr entCellChanged( ByVal sender As Object, ByVal e As System.EventArg s) Handles dgCustomer.Curr entCellChanged
          Dim drArray() As DataRow
          Dim pintFactoryId As Integer
          Dim pintCount As Integer
          Dim pintFactoryName As String
          Dim pintFactoryAddr ess As String

          drArray = DsFactory.tblCu stomer(dgCustom er.CurrentRowIn dex).GetChildRo ws _
          ("drtblCustomer ")

          pintFactoryId = drArray.GetUppe rBound(0) + 1
          txtFactoryId.Te xt = pintFactoryId.T oString

          txtFactoryId.Te xt = pintFactoryId.T oString

          End Sub[/code]

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by kpreston
            Below is the code from Main. Please asvice.
            [code=vbnet]
            Private Sub frmMain_Load(By Val sender As Object, ByVal e As System.EventArg s) Handles MyBase.Load
            Dim printRecords As Integer
            Dim dgtsCustomer As New DataGridTableSt yle()
            Dim dgtsSupplier As New DataGridTableSt yle()
            Dim pbndTemp As Binding
            Dim dtCustomers As DataTable

            ..
            End Sub



            Private Sub dgCustomer_Curr entCellChanged( ByVal sender As Object, ByVal e As System.EventArg s) Handles dgCustomer.Curr entCellChanged
            Dim drArray() As DataRow
            Dim pintFactoryId As Integer
            Dim pintCount As Integer
            Dim pintFactoryName As String
            Dim pintFactoryAddr ess As String

            drArray = DsFactory.tblCu stomer(dgCustom er.CurrentRowIn dex).GetChildRo ws _
            ("drtblCustomer ")

            pintFactoryId = drArray.GetUppe rBound(0) + 1
            txtFactoryId.Te xt = pintFactoryId.T oString

            txtFactoryId.Te xt = pintFactoryId.T oString

            End Sub[/code]
            It appears that you are taking the content from your data set and filling text boxes with the data.

            I don't see where you are changing the view of the dataGrid.
            I still don't understand your use of the "Next" and "Previous" buttons.

            Are you using the Next and Previous buttons to allow the user to update data in your dataSet? Then want to update your dataGrid with this new data showing?

            Can you not just use "RowEditing " and "RowUpdatin g" to allow the user to do their updating in the dataGrid?

            I'm sorry but I still don't understand what you're trying to accomplish.

            -Frinny

            Comment

            • kpreston
              New Member
              • May 2007
              • 4

              #7
              Here is the navigates for first, previous, next and last.
              How can i change datagrid when i click on next or previous. should i create the relationship between factory, customer and supplier. please advice.
              [code=vbnet]
              Private Sub mmuNavigateFirs t_Click(ByVal sender As Object, ByVal e As System.EventArg s) Handles mmuNavigateFirs t.Click
              Me.BindingConte xt(DsFactory3, "tblfactory").P osition = 0
              End Sub


              Private Sub mmuNavigatePrev ious_Click(ByVa l sender As Object, ByVal e As System.EventArg s) Handles mmuNavigatePrev ious.Click
              Me.BindingConte xt(DsFactory3, "tblfactory").P osition -= 1
              End Sub

              Private Sub mmuNavigateNext _Click(ByVal sender As Object, ByVal e As System.EventArg s) Handles mmuNavigateNext .Click
              Me.BindingConte xt(DsFactory3, "tblfactory").P osition += 1

              End Sub

              Private Sub mmuNavigateLast _Click(ByVal sender As Object, ByVal e As System.EventArg s) Handles mmuNavigateLast .Click
              Me.BindingConte xt(DsFactory3, "tblfactory").P osition = Me.DsFactory3.t blFactory.Rows. Count - 1
              End Sub
              [/code]

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Originally posted by kpreston
                Here is the navigates for first, previous, next and last.
                How can i change datagrid when i click on next or previous. should i create the relationship between factory, customer and supplier. please advice.
                [code=vbnet]
                Private Sub mmuNavigateFirs t_Click(ByVal sender As Object, ByVal e As System.EventArg s) Handles mmuNavigateFirs t.Click
                Me.BindingConte xt(DsFactory3, "tblfactory").P osition = 0
                End Sub


                Private Sub mmuNavigatePrev ious_Click(ByVa l sender As Object, ByVal e As System.EventArg s) Handles mmuNavigatePrev ious.Click
                Me.BindingConte xt(DsFactory3, "tblfactory").P osition -= 1
                End Sub

                Private Sub mmuNavigateNext _Click(ByVal sender As Object, ByVal e As System.EventArg s) Handles mmuNavigateNext .Click
                Me.BindingConte xt(DsFactory3, "tblfactory").P osition += 1

                End Sub

                Private Sub mmuNavigateLast _Click(ByVal sender As Object, ByVal e As System.EventArg s) Handles mmuNavigateLast .Click
                Me.BindingConte xt(DsFactory3, "tblfactory").P osition = Me.DsFactory3.t blFactory.Rows. Count - 1
                End Sub
                [/code]
                Please check out MSDN's article on DataGrids and their members and MSDN's Article on DataGrid Events.

                I cannot understand your problem.
                A dataGrid shows many rows...not just one...so there's no need to use "next' and "previous".

                A dataGrid could show all of the rows in your dataSet if you'd like it to...then users just have to glance through the dataGrid to find the row that they'd want to edit.

                A dataGrid also has Paging functionality.. ....which can take you to the first row or the last row in the dataGrid.

                Why can't you just use the update functionality that is built into the dataGrid? Let the user look at the information in the grid, let them select "edit"...le t them edit the information inside the grid....This will simplify your problem quite a bit.

                I'm going to ask other experts to take a look at your problem and hopefully we can help you get through this.

                -Frinny

                Comment

                • giveDsolution
                  New Member
                  • May 2007
                  • 107

                  #9
                  Why dunt u try Gridview Paging...

                  Set Allowpaging true
                  then write the code in vb Page.....

                  Protected Sub GridView1_PageI ndexChanging(By Val sender As Object, ByVal e As System.Web.UI.W ebControls.Grid ViewPageEventAr gs) Handles GridView1.PageI ndexChanging
                  Me.GridView1.Pa geIndex = e.NewPageIndex
                  fillgrid() [Call the fuction to fill gridview]

                  End Sub
                  It may solve ur problem

                  Comment

                  Working...