how to load data in MSflexgrid? the data is not from database:.. like for example, i want to populate first name, last name and address.. how to code this at runtime together with its column name?
Printable View
how to load data in MSflexgrid? the data is not from database:.. like for example, i want to populate first name, last name and address.. how to code this at runtime together with its column name?
Quote:
Originally Posted by joebhoy
Code:Sub LoadMSFlexGrid()
Dim iRow As Integer
Dim iCol As Integer
With MSFlexGrid1
.Rows = 4 ' Including Fixed Row
.Cols = 4 ' Including FixedCol
.FixedCols = 1
.FixedRows = 1
'Generate Column Names
For iCol = 1 To 3
'Code here to give appropriate names
'I am just giving numbers as names
.TextMatrix(0, iCol) = iCol
Next
'Generate Row Names
For iRow = 1 To 3
'Code here to give appropriate names
'I am just giving numbers as names
.TextMatrix(iRow, 0) = iRow
Next
'The data is loaded here
For iRow = 1 To 3
For iCol = 1 To 3
'Replace 0 with the data
.TextMatrix(iRow, iCol) = 0
Next
Next
End With
End Sub
Fullrowselect, is it possible?
what do you mean by Fullrowselect? for inputting data?
i mean, when i click a certain row, it would select the full row..
Quote:
Originally Posted by joebhoy
Code:Private Sub MSFlexGrid1_Click()
With MSFlexGrid1
For I = 1 To .Cols - 1
.ColSel = I
Next
End With
End Sub
To do this programatically, Read more on the property .Rowsel ;)Quote:
Originally Posted by joebhoy
thanx,, got it.. want to ask another Q:
how can i get a value in specific column or row?
Before you add a value to the grid, store that in an array. The grid does not generate its own values, you do. If a user later clicks on a cell and you want the value in the cell to be returned, the row and column then determine the variable and array position.Quote:
Originally Posted by joebhoy
You don't need to store the grid's data in an external array. Use the grid's TextMatrix property to get/set the value of a single cell. Simply pass it the applicable row/col pair.Quote:
how can i get a value in specific column or row?
MSFlexGrid1.TextMatrix(5,4) = "Hello World"
strCellValue = MSFlexGrid1.TextMatrix(5,4)
Also, set the SelectionMode property to flexSelectByRow to get "full row select". Note that it only works when the navigates through the grid with the keyboard or mouse. If you set the current Row or Col in code you must re-select the entire row in code, eg.
Code:with MSFlexGrid1
.Col = .FixedCols
.ColSel = .Cols - 1
end with
Another way is to use the clip property
Code:Private Sub cmdSaveGrid_Click()
Dim MyFile As String
Dim F
Dim Data As String
F = FreeFile
With Grid
.Row = 1
.Col = 1
.ColSel = .Cols - 3 'change for your data
.RowSel = .Rows - 1
Data = .Clip
.Row = 0
.Col = 0
End With
MyFile = App.Path & "\Grid.dat"
On Error Resume Next ' if file doesn't exist, create it
Open MyFile For Binary As #F
Put #F, 1, Data
Close #F
End Sub
'get it back
Private Sub cmdLoadGrid_Click()
Dim MyFile As String
Dim F
Dim Data As String * 550 'adjust this
F = FreeFile
cmdClearQuickGrid_Click
MyFile = App.Path & "\Grid.dat"
On Error Resume Next
Open MyFile For Binary As #F
Get #F, 1, Data
Close #F
With GridQuick
.Row = 1
.Col = 1
.ColSel = .Cols - 3
.RowSel = .Rows - 1
.Clip = Trim(Data)
.Row = 0
.Col = 0
End With
End Sub
thanx... this would greatly helps... :-)