Dear Sir,
I'm Trying to to Export image with based filename on expression datatable in VB.NET
but the results are not appropriate
Please guide me
result from code :
Teatime Chocolate Biscuits,2321456743211.png
Teatime Chocolate Biscuits,2321456743212.png
Teatime Chocolate Biscuits,2321456743213.png
Teatime Chocolate Biscuits,2321456743214.png
Teatime Chocolate Biscuits,2321456743215.png
Desired result :
Mishi Kobe Niku,845723054943.png
Carnarvon Tigers,246321456231.png
Ipoh Coffee,589412354786.png
Aniseed Syrup,457125463254.png
Teatime Chocolate Biscuits,232145674321.png
Imports BaiqiSoft.LabelControl
Public Class Form1
Private m_DataTable As DataTable
Private Sub CreateDataTable()
If m_DataTable IsNot Nothing Then Return
m_DataTable = New DataTable
'Columns
m_DataTable.Columns.Add("ProductName", GetType(String))
m_DataTable.Columns.Add("Barcode", GetType(String))
m_DataTable.Columns.Add("Price", GetType(Single))
m_DataTable.Columns.Add("LabelNumber", GetType(Integer))
m_DataTable.Columns.Add("QTY", GetType(Integer))
m_DataTable.Columns.Add("Filename", GetType(String), "ProductName +','+ Barcode")
'Rows
m_DataTable.Rows.Add("Mishi Kobe Niku", "845723054943", 96.0, 2, 1)
m_DataTable.Rows.Add("Carnarvon Tigers", "246321456231", 61.5, 1, 1)
m_DataTable.Rows.Add("Ipoh Coffee", "589412354786", 46.0, 3, 1)
m_DataTable.Rows.Add("Aniseed Syrup", "457125463254", 10.0, 1, 1)
m_DataTable.Rows.Add("Teatime Chocolate Biscuits", "232145674321", 9.2, 5, 1)
End Sub
Private Sub Btnexport_Click(sender As Object, e As EventArgs) Handles Btnexport.Click
Dim theLabel As New LabelPrinting()
theLabel.LicenseKey = ""
theLabel.OpenLabel(Application.StartupPath & "\test.blf")
Dim count As Integer = 0
For Each row2 As DataGridViewRow In DataGridView1.Rows
Dim isselect As Boolean = Convert.ToBoolean(row2.Cells("checkboxcolumn").Value)
If isselect Then
count += 1
End If
Next row2
Dim selectedRows As DataTable = m_DataTable.Clone
selectedRows.Columns("Filename").Expression = Nothing : selectedRows.Columns("Filename").ReadOnly = False
For Each row2 As DataGridViewRow In DataGridView1.Rows
Dim isselect As Boolean = Convert.ToBoolean(row2.Cells("checkboxcolumn").Value)
If isselect Then
Dim newRow As DataRow = selectedRows.Rows.Add()
newRow("ProductName") = m_DataTable.Rows(row2.Index)("ProductName")
newRow("Barcode") = m_DataTable.Rows(row2.Index)("Barcode")
newRow("Price") = m_DataTable.Rows(row2.Index)("Price")
newRow("LabelNumber") = m_DataTable.Rows(row2.Index)("LabelNumber")
newRow("QTY") = m_DataTable.Rows(row2.Index)("QTY")
newRow("Filename") = m_DataTable.Rows(row2.Index)("Filename")
theLabel.ExportOptions.FileName = newRow("Filename")
End If
Next row2
theLabel.DataSource = selectedRows
theLabel.ExportOptions.Path = Application.StartupPath
theLabel.Label.QuantityColumn = "QTY"
theLabel.ExportOptions.Quantity = QuantityOptions.AllRecords
theLabel.ExportOptions.Format = ImageFormats.Png
theLabel.ExportOptions.Resolution = 300
theLabel.ExportImage()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
CreateDataTable()
DataGridView1.DataSource = m_DataTable
Dim CheckedBoxColumn As New DataGridViewCheckBoxColumn
CheckedBoxColumn.Width = 40
CheckedBoxColumn.Name = "checkboxcolumn"
CheckedBoxColumn.HeaderText = "Check"
DataGridView1.Columns.Insert(0, CheckedBoxColumn)
End Sub
End Class
Below link library BaiqiSoft.LabelControl trial
Link share library demo
Link label sample file