Articles in this section
Category / Section

Load Symbol Palette from DB

2 mins read

Loading symbol palette from Database:

 

In WinForms Diagram Palette the process of binding data from the database can be done only by processing the data available in the table/dataset manually.

 

The below code snippet is used to establish connection between the project and the Database

C#:

            string command = "SELECT * FROM sample";
//Establishing the connection between the project and the database
            using (SqlConnection conn = new SqlConnection(connection))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(command, conn))
                {
                    SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                    adapt.Fill(table);
                }
                conn.Close();
            }
        

 

The below code snippet is used to fetch the data from the database and add the respective nodes from the generated values.

C#:

 
SymbolPalette sym = new SymbolPalette();
            foreach (DataRow row in table.Rows)
            {
                   //Getting the values from the database 
                    string shape = row["Shape"].ToString();
                    float width = float.Parse(row["Width"].ToString());
                    float height = float.Parse(row["Height"].ToString());
                    float x = float.Parse(row["X"].ToString());
                    float y = float.Parse(row["Y"].ToString());            
switch (shape)
                        {
                            case "Eliipse":
                                {
Syncfusion.Windows.Forms.Diagram.Ellipse e = new Ellipse(x, y, width, height);
                                //The created symbol has been appended to the symbolpalette    
                              sym.AppendChild(e);
                                    break;
                                }
                            case "Rectangle":
                                {
                                    Syncfusion.Windows.Forms.Diagram.Rectangle r = new Syncfusion.Windows.Forms.Diagram.Rectangle(x, y, width, height);
                                //The created symbol has been appended to the symbolpalette    
                                    sym.AppendChild(r);
                                    break;
                                }
        }

 

 

VB:

Dim command As String = "SELECT * FROM sample"
‘Establishing the connection between the project and the database
   Using conn As New SqlConnection(connection)
    conn.Open()
    Using cmd As New SqlCommand(command, conn)
     Dim adapt As New SqlDataAdapter(cmd)
     adapt.Fill(table)
    End Using
    conn.Close()
   End Using

The below code snippet is used to populate the nodes from the database and then append it to the symbol palette.

VB:

Dim sym As New SymbolPalette()
   For Each row As DataRow In table.Rows
‘Getting the values from the database
Dim shape As String = row("Shape").ToString()
Dim width As Single = Single.Parse(row("Width").ToString())
Dim height As Single = Single.Parse(row("Height").ToString())
Dim x As Single = Single.Parse(row("X").ToString())
Dim y As Single = Single.Parse(row("Y").ToString())
Select Case shape
Case "Eliipse"
Dim e As Syncfusion.Windows.Forms.Diagram.Ellipse = New Ellipse(x, y, width, height)
‘The created symbol has been appended to the symbolpalette    
sym.AppendChild(e)
Exit Select
Case "Rectangle"
Dim r As New Syncfusion.Windows.Forms.Diagram.Rectangle(x, y, width, height)
‘The created symbol has been appended to the symbolpalette    
sym.AppendChild(r)
Exit Select
Next row

 

Please refer the below attached sample.

Sample

Conclusion

I hope you enjoyed learning about loading Symbol Palette from DB.

You can refer to our WinForms Diagram’s feature tour page to know about its other groundbreaking feature representations. You can also explore our  WinForms Diagram documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms Diagram and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied