Skip to Content
author's profile photo Former Member
Former Member

Delete and Shortcut

Hi all !

i create new Child form .I used Grid and button on form.

1: when display form ,I want to disable key (Ctrl+A) or shortcut (Add) on toolbar to create 1 new record on grid.

2:when i delete some rows on grid (row 1),# column auto decrease ,but it decrease not order.

this is picture 1:before delete

URL=http://imageshack.usIMGhttp://img380.imageshack.us/img380/1317/deleterow1ql0.png[/IMG][/url]

URL=http://g.imageshack.us/img380/deleterow1ql0.png/1/IMGhttp://img380.imageshack.us/img380/deleterow1ql0.png/1/w650.png[/IMG][/url]

this is picture 2:after delete

URL=http://imageshack.usIMGhttp://img383.imageshack.us/img383/6493/afterdeleterow1dz6.png[/IMG][/url]

URL=http://g.imageshack.us/img383/afterdeleterow1dz6.png/1/IMGhttp://img383.imageshack.us/img383/afterdeleterow1dz6.png/1/w646.png[/IMG][/url]

have one problem this case.

This is code that i used:

If pVal.MenuUID = "Remove" Then

If pVal.BeforeAction = True Then

Dim oGrid As SAPbouiCOM.Grid = oForm.Items.Item("MyGrid").Specific

Dim oRows As SAPbouiCOM.DataRows = oGrid.DataTable.Rows

Dim oDataTable As SAPbouiCOM.DataTable = oGrid.DataTable

Dim oRecordSet As SAPbobsCOM.Recordset = Me.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

Dim n3 As Integer

Dim OFormparent As SAPbouiCOM.Form

OFormparent = SBO_Application.Forms.GetForm("60100", 1)

Dim oEdit As SAPbouiCOM.EditText

Dim strVal As String

oEdit = OFormparent.Items.Item("33").Specific

strVal = oEdit.String

If oRows.Count > 0 Then

Dim intRow As Int32 = oGrid.Rows.SelectedRows.Item(0, SAPbouiCOM.BoOrderType.ot_RowOrder)

If intRow >= 0 Then

oCompany.StartTransaction()

n3 = oDataTable.GetValue("#", intRow)

Try

oRecordSet.DoQuery("DELETE FROM child WHERE #='" & n3 & "' and EmpID='" & strVal.ToString() & "'")

Catch ex As Exception

oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)

End Try

End If

oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)

oRows.Remove(intRow)

oForm.Refresh()

End If

Dim n1 As String

Dim b1 As String

Dim n2 As String

Dim n31 As Integer

Dim i As Integer

If oRows.Count > 0 Then

oCompany.StartTransaction()

For i = 0 To oRows.Count - 1

n31 = oDataTable.GetValue("#", i)

n1 = oDataTable.GetValue("Name", i)

b1 = oDataTable.GetValue("Birthdate", i)

n2 = oDataTable.GetValue("Sex", i)

Try

If n31 = 1 Then

oRecordSet.DoQuery("update Child set #='" & n31 & "',Name=N'" & n1 & "',Birthdate='" & b1 & "',Sex=N'" & n2 & "'where #='" & n31 & "'and EmpID='" & strVal.ToString() & "'")

ElseIf n31 >= 1 Then

oRecordSet.DoQuery("update Child set #='" & n31 - 1 & "',Name=N'" & n1 & "',Birthdate='" & b1 & "',Sex=N'" & n2 & "'where #='" & n31 & "'and EmpID='" & strVal.ToString() & "'")

End If

Catch ex As Exception

End Try

Next

oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)

oGrid.DataTable.SetValue("#", oGrid.Rows.Count - 1, oRows.Count)

End If

End If

End If

Thank you !

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Nov 27, 2008 at 03:57 AM

    Hello Vanhuynh,

    You need to refresh the row number when some rows are removed.

    'In the remove row menu hanlder, refresh the row number by looping
    If oRows.Count > 0 Then 
     For i = 0 To oRows.Count - 1
        oDataTable.SetValue("#", i)                         
    Next

    Regards, Yatsea

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 27, 2008 at 05:20 AM

    Hi Li,

    oGrid.DataTable.SetValue(Column as Object,RowIndex as interger,value as object)

    ex:

    oGrid.DataTable.SetValue("#", oGrid.Rows.Count - 1, oGrid.Rows.Count)

    not

    oGrid.DataTable.SetValue("#",i)

    Edited by: Rui Pereira on Dec 23, 2008 4:07 PM

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.