AllenJ
2015-06-05T19:28:21Z
Is there a way to save the grid data in an XML file and then restore it back?

Here's the code I use to save various controls to an XML file, and I would like to add a way the save the iGrid cell data to the same file. Obviously the line

oXMLWriter.WriteElementString(oChild.Name, oGrid.Cells.ToString)

only saves

Quote:

<fgPiles>TenTec.Windows.iGridLib.iGCellCollection</fgPiles>



to the file. Anyway to save the cell data? The number of rows and columns will vary, depending on other factors.


  Private Sub CheckSaveControl(ByVal oChild As Control)

        Select Case True

            Case TypeOf oChild Is ComboBox
                If SaveComboBox Then
                    oXMLWriter.WriteElementString(oChild.Name, oChild.Text.ToString)
                    oXMLWriter.WriteString(vbCrLf)
                End If

            Case TypeOf oChild Is System.Windows.Forms.TextBox Or TypeOf oChild Is MaskedTextBox
                If SaveTextBox Then
                    oXMLWriter.WriteElementString(oChild.Name, oChild.Text.ToString)
                    oXMLWriter.WriteString(vbCrLf)
                End If

            Case TypeOf oChild Is NumericUpDown
                If SaveTextBox Then
                    oXMLWriter.WriteElementString(oChild.Name, oChild.Text.ToString)
                    oXMLWriter.WriteString(vbCrLf)
                End If

            Case TypeOf oChild Is RadioButton
                If SaveRadioButton Then
                    If CType(oChild, RadioButton).Checked Then
                        oXMLWriter.WriteElementString(oChild.Name, "True")
                        oXMLWriter.WriteString(vbCrLf)
                    End If
                End If

            Case TypeOf oChild Is CheckBox
                If SaveCheckBox Then
                    If CType(oChild, CheckBox).Checked Then
                        oXMLWriter.WriteElementString(oChild.Name, "True")
                        oXMLWriter.WriteString(vbCrLf)
                    End If
                End If

            Case TypeOf oChild Is TenTec.Windows.iGridLib.iGrid
                Dim oGrid As TenTec.Windows.iGridLib.iGrid = CType(oChild, TenTec.Windows.iGridLib.iGrid)
                If oGrid.ReadOnly = False Then
                    oXMLWriter.WriteElementString(oChild.Name, oGrid.Cells.ToString)
                    oXMLWriter.WriteString(vbCrLf)
                End If

        End Select

    End Sub
Igor/10Tec
2015-06-08T07:08:14Z
You asked a question regarding iGrid.NET, but this section is dedicated to iGrid ActiveX. I have just moved your question to the proper place.

***

As for the problem itself, we do not provide such a method as there can be a lot of ways of its implementation depending on a particular task. For instance, specific cell data may require specific serialization/deserialization code or you may need to store the current sorting/grouping state. You may want to store column tags or cell aux values, related drop-down lists, various cell formatting properties, and thus the size of the resulting XML file may grow a lot - what you won't like for other 'simple' grid backups.

To help you to build such a tool for your particular task, I can recommend that you look at the Backup Manager sample from our online extra sample library for iGrid.NET:

http://10tec.com/winforms-grid/extra-samples.aspx 

Maybe, we also need to write a similar basic example that demonstrates how to save/restore grid to an XML file. If you have any thoughts regarding that, I would be glad to continue this dialog.
AllenJ
2015-06-11T19:12:31Z
OK, I looked at your example and it gave me an idea. All I really want to save is the values, so I just copied all the cell values into a delimited string and then save/restore the string to the igrid. Thanks!

Saving:

 Case TypeOf oChild Is TenTec.Windows.iGridLib.iGrid
                Dim oGrid As TenTec.Windows.iGridLib.iGrid = CType(oChild, TenTec.Windows.iGridLib.iGrid)
                If oGrid.ReadOnly = False Then
                    Dim CelString As String, DL As String = "|"
                    CelString = oGrid.Rows.Count & DL & oGrid.Cols.Count & DL
                    For r As Integer = 0 To oGrid.Rows.Count - 1
                        For c As Integer = 0 To oGrid.Cols.Count - 1
                            Dim CelVal As String
                            Try
                                CelVal = oGrid.Cells(r, c).Value.ToString
                            Catch ex As Exception
                                CelVal = "---"
                            End Try

                            CelString = CelString & CelVal & DL
                        Next
                    Next
                    oXMLWriter.WriteElementString(oChild.Name, CelString)
                    oXMLWriter.WriteString(vbCrLf)
                End If
Restoring:

            Case TypeOf oChild Is TenTec.Windows.iGridLib.iGrid
                Dim oGrid As TenTec.Windows.iGridLib.iGrid = CType(oChild, TenTec.Windows.iGridLib.iGrid)
                If oGrid.ReadOnly = False Then
                    Dim DL As String = "|", CelList() As String = Split(controlValue, DL), ci As Integer = 2
                    oGrid.Rows.Count = CInt(CelList(0))
                    oGrid.Cols.Count = CInt(CelList(1))
                    For r As Integer = 0 To oGrid.Rows.Count - 1
                        For c As Integer = 0 To oGrid.Cols.Count - 1
                            oGrid.Cells(r, c).Value = CelList(ci)
                            ci += 1
                        Next
                    Next
                End If