Start New Discussion within our Software Development Community

Hello everyone. Here is the code first

Private Sub Grid1_Click()
Dim i As Integer, j As Integer
Grid2.Cols = Grid1.Cols
Grid2.Rows = i + 1
C = Grid1.Row
For j = 0 To Grid1.Cols - 1
Grid2.TextMatrix(i, j) = Grid1.TextMatrix(C, j)
Next j
i = i + 1
End Sub

what I am trying to do here is transfer data from grid1 to grid2. This code is transferring the data, but the problem is:
1) after transferring one row data when I clicked another row of grid1, it just change the existing data of the grid2 to current data. What I want here is to transfer it into next row of grid2 insted of replacing it with the previos row.
2) the first row of grid2 is suppose to hold the headings but the data is shifting to the first row, so I don't have any column heading there.

Hope I can make the qustion clear here. Any kind of help plz.

Thnaks sir for replying. I have the following code now :

Private Sub Grid1_Click()
Dim i As Integer, j As Integer
Grid2.Cols = Grid1.Cols
i = Grid2.Rows
Grid2.Rows = i + 1
C = Grid1.Row
For j = 0 To Grid1.Cols - 1
Grid2.TextMatrix(i, j) = Grid1.TextMatrix(C, j)
Next j
i = i + 1
End Sub

it has solved my two problems but adds a new one. Now I am having a extra row next to my heading of the grid. I mean when I click the grid1 row it adds to grid2 but after leaving an empty row above it. Should I cut something from my code ??

i m uploading the image as attachment here. data is going from sales details to change details. There is a extra row created i change details above the transferred data row. sales_return

Try :

Private Sub grid1_Click()
    With grid2
        a = grid2.Rows - 1
        b = grid1.RowSel

        For j = 1 To grid1.Cols - 1
            grid2.TextMatrix(a, j) = grid1.TextMatrix(b, j)
        Next j
        .AddItem ""
    End With
End Sub

And that solves the problem, thanx JX. :)

Merry Christmas and happy new year so by the way.

Merry Christmas my friend :)

Thanks for the solution JX Man. Although it solves the problem other way around. I mean now when I click a row in grid1 it went to grid2 adding an extra row after the transferred data row, before it was happening an extra row before the data row (as per the picture of my last post), now it is adding an extra row after the data row. I don't know will it be solved or not properly or anything I am doing wrong, but thanks anyway.

is there any other way, I mean using a data-grid or listview or anything elese can solve the problem ??

What you mean about using datagrid or listview?
Transfered it from flexgrid to datagrid/listview or using datagrid/listview for all operation?

what would be the easiest ? Although I have used MSHFlexgrid mostly in this program, but if in this situation any alternative can bring good result, I like to go for it.

Thanks for you attachment and advice. I have used two listview to accomplished the task, till now I am satisfied. Thanks again.

Dear friends
i am making inventory management i have one problem when i have purchase product form its working successufully. other form is edit purchase order. when i click update it does not save. please any one can help me? here is code

private cmdsave_click()
Dim dd1 As Database
Dim mi1 As Recordset
Dim count As Integer
Dim gg As Variant
dbname = App.Path + "\data\database.mdb"
Set dd1 = OpenDatabase(dbname)
Set mi1 = dd1.OpenRecordset("select * from purchase")
bir.Row = 1
bir.Col = 0
    If bir.Text = "" Then
MsgBox "Please enter complete detail.", vbExclamation
For count = 1 To bir.Rows - 2
    bir.Row = count
    bir.Col = 0
    mi1.Fields("proid") = bir.Text
    bir.Col = 1
    mi1.Fields("name") = bir.Text
    bir.Col = 2
    mi1.Fields("packing") = bir.Text
    bir.Col = 3
    mi1.Fields("packtype") = bir.Text
    bir.Col = 4
    mi1.Fields("weight") = bir.Text
    bir.Col = 5
    mi1.Fields("ip") = bir.Text
    bir.Col = 6
    mi1.Fields("tp") = bir.Text 
    bir.Col = 7
    mi1.Fields("purqty") = bir.Text
    bir.Col = 8
    mi1.Fields("purbonus") = bir.Text
    bir.Col = 9
    mi1.Fields("disper") = bir.Text
    bir.Col = 10
    mi1.Fields("disrs") = bir.Text
    bir.Col = 11
    mi1.Fields("wto") = bir.Text
    bir.Col = 12
    mi1.Fields("total") = bir.Text
    bir.Col = 13
    mi1.Fields("discount") = bir.Text
    bir.Col = 14
    mi1.Fields("netamount") = Val(bir.Text)
bir.Col = 15
mi1.Fields("bonusamount") = Val(bir.Text)
bir.Col = 16
mi1.Fields("wtoamount") = Val(bir.Text)
'bir.Col = 17
mi1.Fields("purid") = Combo1.Text
mi1.Fields("purdate") = Label2.Caption
mi1.Fields("company") = Label6.Caption
mi1.Fields("supaddress") = Label7.Caption
mi1.Fields("supphone") = Label8.Caption
mi1.Fields("supfax") = Label15.Caption
mi1.Fields("supemail") = Label11.Caption
mi1.Fields("supwebsite") = Label12.Caption
mi1.Fields("groupname") = Label10.Caption
mi1.Fields("guid") = Label16.Caption
mi1.Fields("comid") = Label14.Caption
bir.FormatString = "Item No | Item Name |Pack Size |Pack Type |Weight |I.Price |T.Price |Qty |Bonus |Dis % |Dis $ |W T O |TOTAL |DISCOUNT |NET AMOUNT |BONUS AMOUNT |WTO AMOUNT"
bir.Rows = 2
End If
Unload Me
End Sub
This question has already been answered. Start a new discussion instead.