2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
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.
|
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.