Datagrids in MicroStation VBA
Datagrids. These things.
Reference Microsoft Datagrid Control 6.0 that's MSDATAGRID.OSX. It's much better than flex grid and you can bind a record set to the grid.
What's interesting here is that the recordset doesn't have to come from a database. You can build it record by record. So, consider this. If you scan a drawing for cells, you could create a record for each cell found and maybe show, level, color, weight, style, name. Maybe even make this data editable. Nice.
That's what I've done for my RTM symbols. Each parcel, remainder, structure, etc can be scanned and loaded into a datagrid. The data that I store in each of these cells is displayed as a grid record. Click on a record it highlights the cell. I do this by including in the record the element.id.low value.
So, when my form with the data grid is loaded (see image) I do something like this.
Set r = New ADOR.Recordset
r.fields.Append "Symbol", adVarChar, 255
r.fields.Append "Tract", adVarChar, 255
r.fields.Append "Type", adVarChar, 255
r.fields.Append "No/Letter", adVarChar, 255
r.fields.Append "Total", adVarChar, 255
r.fields.Append "ID", adVarChar, 255
r.CursorType = adOpenDynamic
r.Open
populateRecordSet
Then configure the datagrid
Set DataGrid1.DataSource = r
Me.DataGrid1.Caption = "Symbols"
I set the column widths and lock some of the columns too.
The recordset is populated in this manner. (watch the line wraps, my blogger style isn't really designed for code. need to do something about that.)
Private Sub PopulateRecordSet()
Dim oScanCriteria As ElementScanCriteria
Set oScanCriteria = New ElementScanCriteria
oScanCriteria.ExcludeAllTypes
oScanCriteria.IncludeType _
msdElementTypeCellHeader
Dim oScanEnumerator As ElementEnumerator
Set oScanEnumerator = _
ActiveModelReference.Scan(oScanCriteria)
Dim oElement As element, oCell As CellElement
Do While oScanEnumerator.MoveNext
Set oCell = oScanEnumerator.Current
Dim sym As String, tract As String
Dim sType As String, num As String
Dim total As String
If ReadDataFromCell(oCell, _
sym, tract, sType, num, total) Then
r.AddNew
r.fields(0).Value = sym
r.fields(1).Value = tract
r.fields(2).Value = sType
r.fields(3).Value = num
r.fields(4).Value = total
r.fields(5).Value = _
Str(oCell.FilePosition)
End If
Loop
End Sub
I've used this in several places now. It's easy to configure and works well with MicroStation scans.



0 Comments:
Post a Comment
<< Home