现在有两个 vsflexgrid1  和 vsflexgrid2 
通过什么样的方法将 vsflexgrid1表格的内容复制到 vsflexgrid2 ???

解决方案 »

  1.   

    你当初这么在 vsflexgrid1  和 vsflexgrid2 上显示数据的,现在反过来写或者:
    用一个二维数组做中间变量
      

  2.   

    很简单:
    vsflexgrid2.BindToArray  vsflexgrid1
      

  3.   

    呵呵,在vsflexgrid中有一个属性vsflexgrid1.textmatrix(x,y)可直接读取任意单元格的内容,x是row,y是col可以写一个双重循环,先把第一行的数据复制过去,再复制第二行,第三行......
    或是先复制第一列,第二列,第三列.......
    很简单的,你可以试试另外,楼上写的vsflexgrid2.bindtoarray vsflexgrid1中的bindtoarray属性是什么啊,我没用过,我也是刚刚才用vsflexgrid控件的,我找了一个简单的中文说明,说明中没写到bindtoarray这个方法,你能告诉我这个 方法是做什么用的嘛?谢谢
      

  4.   

    BindToArray MethodBinds the grid to an array of variants to be used as storage.Syntax[form!]VSFlexGrid.BindToArray [ VariantArray As Variant ], [ RowDim As Long ], [ ColDim As Long ], [ PageDim As Long ], [ CurrentPage As Long ]ResThis method allows you to bind the VSFlexGrid control to a Visual Basic Variant Array or to another VSFlexGrid control.When bound to an array, the grid displays values retrieved from the array and automatically writes any modifications back into the array. The array must have at least two dimensions and it must be an array of Variants. If the array has more than two dimensions, you may use the control to display one "page" of it at a time, and you may easily "flip pages".The parameters on this method allow you to control how the rows and columns map onto the array's dimensions. By default, columns bind to the first array dimension (0) and rows bind to the second array dimension (1). This is the order used by ADO when returning recordsets with the GetRows method. The advantage of this default setting is that you may add or remove rows while preserving existing data using Visual Basic's Redim Preserve statement, which only allows the last dimension to be modified. If you don't like the default setting, you may define things differently.The mapping is always from LBound to UBound on all dimensions. If you want to hide some rows or columns, set their height or width to zero. The binding does not apply to fixed rows or columns. It works only for the scrollable (data) part of the control.If you change the contents or dimensions of the array, you should tell the control to repaint itself so the changes become visible to the user. You may do this with the Refresh method or by using the BindToArray method again.To unbind the control, call the BindToArray method with a Null parameter:    fg.BindToArray NullThe example below illustrates several variations on this theme. The demo project included in the distribution package has more examples.    ' ** Two-dimensional binding:
        Dim arr(4, 8)    ' Default binding:
        fg.BindToArray arr
        ' fg now has 5 non-fixed columns (0-4) and 9 non-fixed rows (0-8).
        ' the mapping is: arr(i, j) = fg.TextArray(j - fg.FixedRows, i - fg.FixedCols)    ' Transposed binding:
        fg.BindToArray arr, 0, 1
        ' fg now has 9 non-fixed columns (0-8) and 5 non-fixed rows (0-4).
        ' the mapping is: arr(i, j) = fg.TextArray(i - fg.FixedRows, j - fg.FixedCols)    ' ** Three-dimensional binding (AKA cube, notebook):
        ReDim arr(4, 8, 12)
        
        ' Default binding:
        fg.BindToArray arr
        ' by default, the last dimension becomes the "pages", and the 
        ' current page is the first (0), so
        ' fa now has 5 non-fixed columns (0-4) and 9 non-fixed rows (0-8).
        ' the mapping is: arr(i, j, 0) = fg.TextArray(j - fg.FixedRows, i - fg.FixedCols)    ' Page Flipping:    fg.BindToArray arr, , , , 2    ' the row, col, and page settings are the default, and the current    ' page is 2 (instead of the default 0), so    ' fg now has 5 non-fixed columns (0-4) and 9 non-fixed rows (0-8).
        ' the mapping is: arr(i, j, 2) = fg.TextArray(j - fg.FixedRows, i - fg.FixedCols)
      The BindToArray method also allows you to bind the control to another VSFlexGrid control. This way, you may create different "views" of the same data without having to keep duplicate copies of the data. The syntax is the same:    fg.BindToArray fgSourceIn this case, the fg control will display the data stored in the fgSource control. Changes to cells in either control will reflect on the other. When binding to another VSFlexGrid control, the fixed cells are bound as well as the scrollable ones. The binding only applies to the data, not to the cell formats.To load data from an array or another VSFlexGrid control without binding, use the LoadArray method instead.
      

  5.   

    dim i as integer
    dim y as integer
    y=0
    for i=0 to 最大行
       vsflexgrid2.textmatrix(i,y)=vsflexgrid1.textmatrix(i,y)
    next这是只复制一行的方法,里面再套一个循环即可全复制了.
      

  6.   

    yxfloveann(蜂蜂)<<很简单:
    vsflexgrid2.BindToArray  vsflexgrid1>>可行。
    还有保存为交换文件也可实现!(本人作过)
      

  7.   

    dim i as integer
    dim y as integer
    y=0
    for i=0 to 最大行
       vsflexgrid2.textmatrix(i,y)=vsflexgrid1.textmatrix(i,y)
    next这是只复制一行的方法,里面再套一个循环即可全复制了.最无效率的办法!
      

  8.   

    用Clip行不
    整个COPY,后贴上就行了,不知道速度如何,应该比循环好点吧
      

  9.   

    yxfloveann(蜂蜂)<<很简单:
    vsflexgrid2.BindToArray  vsflexgrid1>>可行。
    还有保存为交换文件也可实现!(本人作过)
    严重同意这两种作法.....我记得前些天回答了一个MSHFlexgrid复制数据的方法,但是在两个不同的窗体间.我记得直接用对象实现了.不过这个我在一个窗体中试了半天没弄出来.