)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Load Symbol Palette from DB

Platform: WinForms |
Control: Diagram |
Published Date: November 25, 2015 |
Last Revised Date: June 2, 2019
Tags: diagram

Loading symbol palette from Database:

 

In 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

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon