Click here to Skip to main content
15,885,998 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a form in which i have choose 2 gridview control . i have fetch data from data base in one grid and given a check box column on it . i want to set the value of all grid column in another grid on the click of button after select check box .I have try a code mention below it is an window form application

What I have tried:

With dsDetail.Tables(0)
                   For iCount = 0 To .Rows.Count - 1
                       'If Val(.Rows(iCount).Item("BalanceAmount")) > 0 Then
                       If .Rows(iCount).Item("Checked") = 1 Then
                           ''' If dsMain.Tables("Detail").Rows.Count - 1 >= 0 Then
                           '''  For i = 0 To dsMain.Tables("Detail").Rows.Count - 1
                           'If dsDetail.Tables(0).Rows(i).Item("IdSInvoiceH") <> dsMain.Tables("Detail").Rows(iCount).Item("IdSInvoiceH") Then
                           '    drHeader = dsMain.Tables("Detail").NewRow
                           '    'drHeader.Item("AgainstType") = cboPartyName.Value
                           '    drHeader.Item("IdPartyH") = cboPartyName.Value
                           '    drHeader.Item("IdSInvoiceH") = .Rows(iCount).Item("IdSInvoiceH")
                           '    drHeader.Item("RefNo") = .Rows(iCount).Item("RefNo")
                           '    drHeader.Item("RefDate") = .Rows(iCount).Item("RefDate")
                           '    drHeader.Item("PartyDocNo") = .Rows(iCount).Item("PartyDocNo")
                           '    drHeader.Item("PartyDocDate") = .Rows(iCount).Item("PartyDocDate")
                           '    drHeader.Item("Amount") = .Rows(iCount).Item("Amount")
                           '    drHeader.Item("Checked") = .Rows(iCount).Item("Checked")
                           '    drHeader.Item("BalanceAmount") = .Rows(iCount).Item("BalanceAmount")
                           '    dsMain.Tables("Detail").Rows.Add(drHeader)
                           'End If
                           'Next
                           '' Else
                           drHeader = dsMain.Tables("Detail").NewRow
                           'drHeader.Item("AgainstType") = cboPartyName.Value
                           drHeader.Item("IdPartyH") = CboPartyName.Value
                           drHeader.Item("IdSInvoiceH") = .Rows(iCount).Item("IdSInvoiceH")
                           drHeader.Item("RefNo") = .Rows(iCount).Item("RefNo")
                           drHeader.Item("RefDate") = .Rows(iCount).Item("RefDate")
                           drHeader.Item("PartyDocNo") = .Rows(iCount).Item("PartyDocNo")
                           drHeader.Item("PartyDocDate") = .Rows(iCount).Item("PartyDocDate")
                           drHeader.Item("Amount") = .Rows(iCount).Item("Amount")
                           drHeader.Item("Checked") = .Rows(iCount).Item("Checked")
                           'drHeader.Item("BalanceAmount") = .Rows(iCount).Item("BalanceAmount")
                           drHeader.Item("Doc") = cboAdvType.Text
                           dsMain.Tables("Detail").Rows.Add(drHeader)
                       End If
                       '' End If
                   Next
               End With

               ''---------------------
               Dim totalamount As Double
               'Dim rwcounth As Integer
               Dim counth As Integer
               Dim countd As Integer
               Dim ipartycode As Integer
               If gStrPayMode = "CASH" Then
                   For counth = 0 To dsMain.Tables("Header").Rows.Count - 1
                       ipartycode = dsMain.Tables("Header").Rows(counth).Item("IdPartyH")
                       For countd = 0 To dsMain.Tables("Detail").Rows.Count - 1
                           If grdDetail.ActiveRow.Cells("Checked").Value = 1 Then
                               If ipartycode = dsMain.Tables("Detail").Rows(countd).Item("IdPartyH") Then
                                   totalamount = totalamount + dsMain.Tables("Detail").Rows(countd).Item("Amount")
                               End If
                           End If
                       Next
                       If IsDBNull(dsMain.Tables("Header").Rows(counth).Item("AdvType")) Then
                           dsMain.Tables("Header").Rows(counth).Item("AdvType") = ""
                       End If
                       If dsMain.Tables("Header").Rows(counth).Item("AdvType") <> "Open" Then
                           dsMain.Tables("Header").Rows(counth).Item("Amount") = totalamount
                       Else
                           dsMain.Tables("Header").Rows(counth).Item("Amount") = dsMain.Tables("Header").Rows(counth).Item("Amount")
                       End If

                   Next
               Else
                   For counth = 0 To dsMain.Tables("Header").Rows.Count - 1
                       totalamount = 0
                       ipartycode = dsMain.Tables("Header").Rows(counth).Item("IdPartyH")
                       For countd = 0 To dsMain.Tables("Detail").Rows.Count - 1
                           'If grdDetail.ActiveRow.Cells("Checked").Value = 1 Then
                           If ipartycode = dsMain.Tables("Detail").Rows(countd).Item("IdPartyH") Then
                               totalamount = totalamount + dsMain.Tables("Detail").Rows(countd).Item("Amount")
                           End If
                           'End If
                       Next
                       dsMain.Tables("Header").Rows(counth).Item("Amount") = totalamount
                       If IsDBNull(dsMain.Tables("Header").Rows(counth).Item("AdvType")) Then
                           dsMain.Tables("Header").Rows(counth).Item("AdvType") = ""
                           If dsMain.Tables("Header").Rows(counth).Item("AdvType") <> "Open" Then
                               dsMain.Tables("Header").Rows(counth).Item("Amount") = totalamount
                           Else
                               dsMain.Tables("Header").Rows(counth).Item("Amount") = dsMain.Tables("Header").Rows(counth).Item("Amount")
                           End If
                       Else
                       End If
                   Next
               End If

               ''------------------
               grdMain.DisplayLayout.Bands(1).Columns("IdPartyH").Hidden = True
               'grdMain.DisplayLayout.Bands(1).Columns("IdSInvoiceH").Hidden = True
               grdMain.DisplayLayout.Bands(1).Columns("Checked").Hidden = True
               grdMain.DisplayLayout.Bands(1).Columns("IdAccReceiptDocD").Hidden = True
           End If

           grdMain.DataSource = dsMain
           grdMain.DataBind()
Posted
Comments
Richard MacCutchan 24-Apr-17 7:29am    
What is the question?
NightWizzard 24-Apr-17 13:28pm    
If you bind a grid to a database table (or query result) you can't insert rows directly to the grid - do the neccessary operations direczly at the database table and the grid will update automatically.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900