Adding a writable column to a read only Data grid
Hi people !
I need to add a column in a dataGrid that is writable while the rest of the Grid columns are read only.
The dataGrid is bound to a data base so I don't want to give access to its values, but on the other hand, I want to present values for each row in an extra column that is visibly a part of the grid.
Help is highly appreciated !
Thanks,
Oren.
~&-)
Re: Adding a writable column to a read only Data grid
If your datagrid is bound to the db I think you cannot add another column. You can use unbound grid (I prefere MSFlexGrid), populate it with the records from the database and add an extra column where you will allow to write data. Here you will have more flexibility because you will control the whole process.
Good luck
Iouri Boutchkine
[email protected]
Re: Adding a writable column to a read only Data grid
Hi;
What minimal steps do I need to make to populate a grid with records ?
~&-)
Re: Adding a writable column to a read only Data grid
If you use an MSFlexGrid control to display data returned in an ADO recordset, you can use this code to
dynamically populate the grid-including the header row-with the information in the recordset. You need an
open ADO recordset named rst and a form containing an MSFlexGrid control named msfGrid:
Dim cln As Field
With msfGrid
.Rows = 2
.Cols = rst.Fields.Count
'get the number of grid cols
.FixedRows = 1
.FixedCols = 0
.Row = 0
.Col = 0
For Each cln In rst.Fields
.Text = cln.Name
'populate header row with names of fields
If .Col < .Cols - 1 Then .Col = .Col + 1
Next
Do While Not rst.EOF
'loop thru recordset to populate grid
.Row = rst.AbsolutePosition
'move to the next row
.Col = 0
'reset ourselves back to column(0)
For Each cln In rst.Fields
If Not IsNull(cln.Value) Then
.Text = Trim(CStr(cln.Value))
Else
.Text = ""
End If
If .Col < .Cols - 1 Then .Col = .Col + 1
Next
rst.MoveNext
.Rows = .Rows + 1
'add a new row to the grid
Loop
.Rows = .Rows - 1
'remove the last row because it's blank
.Row = 0
End With
Iouri Boutchkine
[email protected]
Re: Adding a writable column to a read only Data grid
Hi !
What I did finally was to use two recordsets. I fill one (A) from the database using an sql statement and append as many fields as I need to the other one (B). Then I add new filds to B with values from A. Eventually, I set the DataGrid.DataSource to be B:
(USING A DATAGRID AND NOT A FLEXGRID)
Set IOChannelsGrid.DataSource = rs
I tried your example and found some difficulties so I gave it up for now not needing it actually.
Thanks !!
~&-)