In a msflexgrid control , i want to give the option to the user to select a single row or a group of rows from msflex grid control the if
use clickon the product_id from first msflexgrid contrl1 since this
grid contains complete list of product_id it selected record should
come on another msflexgrid2
Kindly help me.

i have written a code like that :
Private Sub Form_Load()
Set con = New Connection
con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\asfserver\itp$\Product_tabletest.mdb")
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
Combo1.AddItem "ADMIN & IT"
Combo1.AddItem "SALES"
Combo1.AddItem "ENGINEERING"
Combo1.AddItem "MAINTENANCE"
Combo1.AddItem "MANUFACTERING"
Combo1.AddItem "FINANCE"
Combo1.AddItem "QUALITY CONTROL"
Text13.Locked = Not editing
MSFlexGrid1.FixedRows = 1
MSFlexGrid1.FillStyle = flexFillRepeat
MSFlexGrid1.ColWidth(0) = 1000
MSFlexGrid1.ColWidth(1) = 3500
MSFlexGrid1.ColAlignment(0) = 4
MSFlexGrid1.ColAlignment(1) = 4
MSFlexGrid1.ColAlignment(2) = 4
MSFlexGrid1.Row = 1
MSFlexGrid1.Col = 0
MSFlexGrid1.RowSel = 5
MSFlexGrid1.Cols = 10 'Set dimensions of flexgrid and set selection behaviour
MSFlexGrid1.Rows = 10 'displaying grid
On Error Resume Next
MSFlexGrid1.CellFontBold = True
MSFlexGrid1.CellAlignment = 4
MSFlexGrid1.Font = "Arial"
MSFlexGrid1.TextMatrix(0, 0) = "Product_id"
MSFlexGrid1.TextMatrix(0, 1) = "Product_name"
MSFlexGrid1.TextMatrix(0, 2) = "Unit"
MSFlexGrid1.TextMatrix(0, 3) = "Quantity"
Dim R, C
Set rs = New Recordset
rs.CursorLocation = adUseClient
rs.Open "select distinct item_code,Productname,unit from partdetail ", con, adOpenDynamic, adLockOptimistic
If rs.RecordCount > 0 Then
Do Until rs.EOF
R = R + 1
For C = 0 To 4 Step 1
MSFlexGrid1.Rows = rs.RecordCount + 1
MSFlexGrid1.TextMatrix(R, C) = rs.Fields(C).Value
Next
rs.MoveNext
Loop
End If
End Sub

Hi,

Place a CommandButton "Populate" in the Frame,
Initially, Make Grid2.Rows = 1.

Select a Row, in First Grid, and Click On "Populate", write this code for commandClick.

Dim i As Integer
If Grid1.Row > 0 Then
  Grid2.Rows=Grid2.Rows+1
  With Grid2
    .TextMatrix(.Rows-1, 0) = Grid1.TextMatrix(.Row,0)
    .TextMatrix(.Rows-1, 1) = Grid1.TextMatrix(.Row,1)
    .TextMatrix(.Rows-1, 2) = Grid1.TextMatrix(.Row,2)
    .TextMatrix(.Rows-1, 3) = Grid1.TextMatrix(.Row,3)
  End With
End If

Regards
Veena

as per your suggestion i have written a code in populate_click
Private Sub populate_Click()
MSFlexGrid2.Row = 4
Dim i As Integer
If MSFlexGrid1.Row > 0 Then
MSFlexGrid2.Rows = MSFlexGrid2.Row + 1
MSFlexGrid2.TextMatrix(MSFlexGrid1.Row - 1, 0) = MSFlexGrid1.TextMatrix(MSFlexGrid2.Row, 0)
MSFlexGrid2.TextMatrix(MSFlexGrid1.Row - 1, 1) = MSFlexGrid1.TextMatrix(MSFlexGrid2.Row, 1)
MSFlexGrid2.TextMatrix(MSFlexGrid1.Row - 1, 2) = MSFlexGrid1.TextMatrix(MSFlexGrid2.Row, 2)
MSFlexGrid2.TextMatrix(MSFlexGrid1.Row - 1, 3) = MSFlexGrid1.TextMatrix(MSFlexGrid2.Row, 3)
End If
End Sub

but when i select multiple record got error Subscript out of range
Run time error 381

Kindly help me

Hi,

You have messed the code..
change to :

MSFlexGrid2.TextMatrix(MSFlexGrid1.Rows - 1, 1 ) = MSFlexGrid1.TextMatrix(MSFlexGrid2.Row, 1)

Also, why you are hardcoding rows=4..?
MSFlexGrid2.Row = 4 ' -->> Why This Line..?

Regards
Veena

Private Sub Command5_Click()
Dim i As Integer
If MSFlexGrid2.Row > 0 Then
MSFlexGrid2.Rows = MSFlexGrid2.Row + 1
MSFlexGrid2.TextMatrix(MSFlexGrid1.Rows - 1, 0) = MSFlexGrid1.TextMatrix(MSFlexGrid2.Row, 0)
MSFlexGrid2.TextMatrix(MSFlexGrid1.Rows - 1, 1) = MSFlexGrid1.TextMatrix(MSFlexGrid2.Row, 1)
MSFlexGrid2.TextMatrix(MSFlexGrid1.Rows - 1, 2) = MSFlexGrid1.TextMatrix(MSFlexGrid2.Row, 2)
MSFlexGrid2.TextMatrix(MSFlexGrid1.Rows - 1, 3) = MSFlexGrid1.TextMatrix(MSFlexGrid2.Row, 3)
End If
End Sub

since i am checking If MSFlexGrid2.Row > 0 Then
that is why i put msflexgrid2.row=4

right now i am getting run time error 381
help me please .

CHANGE SECOND LINE TO :

MSFlexGrid2.Rows = MSFlexGrid2.Rows + 1

Everytime, you populate a row is added..

Regards
Veena

which second line i changed second line is already :
MSFlexGrid2.Rows = MSFlexGrid2.Rows + 1

This question has already been answered. Start a new discussion instead.