Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Make some rows read only...

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Make some rows read only...
Link Posted: 03-Dec-2005 11:24
If I am using the following code to add a row to my FlyGrid


Dim data As Object() = New Object() {attName, attDesc, attVisible, attPipeVisible, attIsoVisible, attMode}
                Me.flyGrid.Rows.Items.Add(New Node(data))


But I wanted some rows (not all) to be Read Only, could you please show me how I would code that in VB.Net.

Thank you

Simon
Link Posted: 03-Dec-2005 12:36
You can use FlyGrid.IsReadOnly event to make some rows read-only.
Link Posted: 04-Dec-2005 01:05
I'm affraid I'm still not clear on how to do this.

What I have is a DB table that holds a list of all the rows that I add to the FlyGrid (with the code shown above). One of the columns within the DB is a boolean column called ReadOnly. What I want to be able to do 1) change the colour of this row to yellow and 2) stop any node cells within that row from being modified if the ReadOnly column is true.

E.g.


            Dim myCmd As New OleDb.OleDbCommand("spQryAllAtt")
            myCmd.CommandType = CommandType.StoredProcedure

            Dim myProjectReader As OleDb.OleDbDataReader = Nothing
            myProjectReader = myDB.RunMyDataQuery(myCmd)

            Dim attName As String
            Dim attDesc As String
            Dim attVisible As Boolean
            Dim attPipeVisible As Boolean
            Dim attIsoVisible As Boolean
            Dim attMode As String
            Dim attReadOnly As Boolean

            Do While myProjectReader.Read
                attName = myProjectReader.Item("name")
                attDesc = myProjectReader.Item("description")
                attVisible = myProjectReader.Item("visible")
                attPipeVisible = myProjectReader.Item("pipeVisible")
                attIsoVisible = myProjectReader.Item("isoVisible")
                attMode = myProjectReader.Item("mode")
                attReadOnly = myProjectReader.Item("ReadOnly")

                Dim data As Object() = New Object() {attName, attDesc, attVisible, attPipeVisible, attIsoVisible, attMode}
                Me.FlyGrid1.Rows.Items.Add(New Node(data))

                ' If variable attReadOnly is equal to true then my the row
                ' yellow and make readonly
                If attReadOnly = True then
                  ' Add the readonly code here
                Endif

            Loop

            myDB.DisConnect()


Thank you
Link Posted: 05-Dec-2005 19:37
In this case you can add to FlyGrid unvisible(hidden) column (last column fro example), init node as following:

Dim data As Object() = New Object() {attName, attDesc, attVisible, attPipeVisible, attIsoVisible, attMode, attReadOnly }


and analyze this data in the IsReadOnly event:

bool isReadOnly = (bool)node("ReadOnly")
return isReadOnly


or you can create your own type of Node with ReadOnly property that will initialized in your procedure:

Dim data As Object() = New Object() {attName, attDesc, attVisible, attPipeVisible, attIsoVisible, attMode}
Dim newNode as NodeWithReadOnly = New NodeWithReadOnly(data)
newNode.ReadOnly = attReadOnly
Me.FlyGrid1.Rows.Items.Add(newNode)


In this case your code in the IsReadOnly will:

Dim nodeRO as NodeWithReadOnly = CType(node, NodeWithReadOnly)
return nodeRO.ReadOnly
Link Posted: 06-Dec-2005 09:48
There does not seem to be a NodeWithReadOnly only a NodeWithPlusButton???

Also how would I change the colour of the readonly rows to yellow??

Thanks

Simon
Link Posted: 07-Dec-2005 01:54
See this topic for the read-only nodes sample code.
and this topic for the custom colored nodes sample code.
Link Posted: 07-Dec-2005 07:54
I have done as you said created a new Class etc. that's all fine. The problem is that I get the following error with the below code:

Error: Value of type 'String' cannot be converted to 'NineRays.Windows.Forms.Data.NodeBase'


                Dim data As Object() = New Object() {attName, attDesc, attVisible, attPipeVisible, attIsoVisible, attMode}
                Dim newNode As nodeWithReadOnly = New nodeWithReadOnly(data)
                newNode.ReadOnly = attReadOnly


Any halp you could give me would be really appreshiated.

Thank you

Simon
Link Posted: 07-Dec-2005 16:57
Simply remove NodeWithReadOnly constructor or add this constructor:

public NodeWithReadOnly(object value) : base(value){}
Link Posted: 07-Dec-2005 17:21
BTW, in the prepared for release new version of FlyGrid, support of ReadOnly will embedded.
You can use NodeBase.ReadOnly property to set node into ReadOnly state, this state will supported FlyGrid to prevent node with ReadOnly = true from editing. IsReadOnly event can be used to dynamically enable/disable node editing and will called even node.ReadOnly == true.