Click to See Complete Forum and Search --> : can lock a column


hoa01206
August 13th, 2001, 03:25 PM
Hello all,

I am still working on finding a way to lock a column in MSFlexGrid. I would like to be able to lock a column of choice from that Grid, so when I scroll left or right it will stay fixed. But, the other column will move left or right. Is there anything that can be done to accomplish this task?

Thank you very much in advance
hisham

Thanks
Hisham

Ghost308
August 13th, 2001, 03:29 PM
What if you created one flex grid that contained nothing but the first column, then created another that held all the other columns. You could probably play with the border settings to make them joined like one flexgrid, but only the 2nd one would be scrollable. If there is a programatic way (or even a property) that would accomplish this easier in vb, I haven't seen it. Good luck!

michi
August 13th, 2001, 05:37 PM
I did it before using the same way, but I can't find it right now. If you do need the source codes, I will check it out and tell you tomorrow. Good luck!

Regards,

Michi

hoa01206
August 14th, 2001, 07:23 AM
Thank you so much.

Hisham

Thanks
Hisham

michi
August 14th, 2001, 12:04 PM
Hi,
I just looked up MSDN, and found the properties:
FixedCols and FixedRows. I think what you need is FixedCols.

The following is my test codes. I am pretty sure I didn't use this before, since I need to edit the fixed cols but this approach can't. Anyway, it works fine. Enjoy!
======
Private Function LoadData() As Boolean
On Error GoTo LoadData_Error

Dim strSQL As String 'The SQL Command to execute
Dim rsRecord As ADODB.Recordset 'Recordset for holding loaded record.
Dim rownum As Integer
Dim icount As Integer
Dim strDBField() As String

LoadData = False

'
' Create object
'
Set rsRecord = New ADODB.Recordset

'
'Build up SQL string
'
strSQL = "select ShipmentID,ShipmentType,TransportationType,CreationDate from TSDATA_shipment"

'
' Attempt to load in the database record. gadoConn is the global connection in my project, change it to yours.
'
Call rsRecord.Open(strSQL, gadoConn, adOpenStatic, adLockReadOnly)

'
' Process record if successfully loaded.
'

If Not rsRecord.EOF And rsRecord.RecordCount > 0 Then

ReDim strDBField(3)
strDBField(0) = "ShipmentID"
strDBField(1) = "ShipmentType"
strDBField(2) = "TransportationType"
strDBField(3) = "CreationDate"

' Create number of columns to equal, at least, number of fields.

If MSFlexGrid1.Cols < UBound(strDBField, 1) + 1 Then
MSFlexGrid1.Cols = UBound(strDBField, 1) + 1
End If


' Populate grid header with field names.
For icount = 0 To UBound(strDBField, 1)
MSFlexGrid1.TextMatrix(0, icount) = strDBField(icount)
Next

' Fill grid with data from field(s) in the table.
rsRecord.MoveFirst
rownum = 0
Do Until rsRecord.EOF
rownum = rownum + 1
MSFlexGrid1.AddItem ""
MSFlexGrid1.Row = rownum
For icount = 0 To UBound(strDBField, 1)
MSFlexGrid1.Col = icount
MSFlexGrid1.Text = _
rsRecord.Fields(strDBField(icount))
Next
rsRecord.MoveNext ' Move to next record in table.
Loop

'Set the fixed cols. I just locked 2 cols, you can change it.
MSFlexGrid1.FixedCols = 2

End If


rsRecord.Close
Set rsRecord = Nothing

LoadData = True

Exit Function

LoadData_Error:
LoadData = False
If (rsRecord.State = adStateOpen) Then
rsRecord.Close
End If
Set rsRecord = Nothing

End Function
=====



Regards,

Michi

michi
August 15th, 2001, 11:16 AM
Hi,
I found my previous codes yesterday, but it is not MSFlexGrid. What I used before is DataGrid, and its Splits property.
First, on the form layout, split the grid to two splits. And then use a proper DataSource.
In codes, connect to DB first, and then call Grid1.Rebind. The last thing is creating a function like following to do some make-up on the grid.
=========
Sub FormatGrid()
'
'Lock some columns as you said
'
Const LockedItems = 4

'
'Hide the right part columns in the left split
'
For i = LockedItems To Grid1.Splits(0).Columns.count - 1
Grid1.Splits(0).Columns(i).Visible = False
Next i

'
'Show the right part columns in the right split
'
For i = LockedItems To Grid1.Splits(1).Columns.count - 1
Grid1.Splits(1).Columns(i).Visible = True
Grid1.Splits(1).Columns(i).Alignment = 2
Next i

'
'Show the left part columns in the left split, and hide in the right split
'
For i = 0 To LockedItems - 1
Grid1.Splits(0).Columns(i).Visible = True
Grid1.Splits(0).Columns(i).Alignment = 2
Grid1.Splits(1).Columns(i).Visible = False
Next i

'''''''Refresh Grid''''''''
Grid1.Refresh

'
'set focus to the right split
'
Grid1.Split = 1

End Sub
========
For more information, please look up MSDN, key words: DataGrid and Splits property.

Regards,

Michi