EDN Admin
Well-known member
I have been reading on here for a couple days trying to get an idea of how to accomplish this.
I have a form that connects to an Access database via a Dataset.<br/>
I have a form containing a listbox. This listbox is filled by a column in Table2, so it contains over 100 items.<br/>
When a user runs the program and selects a single listbox item, it should filter Table1 so that only the records matching the selection exist.
Table1 has multiple fields that will need to be printed. They are:
Store (Number)<br/>
SKU (Number)<br/>
Vendor_Name (Text)<br/>
Vendor_VSN (Text)<br/>
SKU_Desc (Text)<br/>
MSRP (Currency)<br/>
Price (Currency)<br/>
Change (Number)<br/>
Section (Number)<br/>
Row (Number)<br/>
Quantity (Number)
I have created textboxes associated with these fields. I would like them to be populated by my listbox selection. Here is what I have so far, but I am not sure if I am missing something with the query, or how I should write the code for the textbox to retrieve
data from my source:
<pre class="prettyprint lang-vb Option Strict On
Option Explicit On
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
StoreManagement.Show()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.StoresTableAdapter3.Fill(Me.JDADS.Stores)
Me.JDATableAdapter1.Fill(Me.JDADS.JDA)
Dim storeNums = From dr As JDADS.StoresRow In JDADS.Stores _
Select dr.StoreNum Distinct Order By StoreNum
For Each storeNum As Double In storeNums
ListBox1.Items.Add(storeNum.ToString)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ListBox1.SelectedIndexChanged
Dim lst As List(Of JDADS.JDARow)
If Not Integer.TryParse(ListBox1.Items(ListBox1.SelectedIndex).ToString, 1) Then
Console.WriteLine(ListBox1.SelectedItem.ToString)
Throw New Exception("Something Went Wrong!")
Else
Dim qry = From dr As JDADS.JDARow In JDADS.JDA _
Where dr.store = CInt(ListBox1.Items(ListBox1.SelectedIndex).ToString)
lst = qry.ToList
End If
set value to textbox or smt else from the first row of result.
....
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
PrintSmLabels.PrinterSettings.Copies = 1
PrintSmLabels.Print()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
PrintBigLabels.PrinterSettings.Copies = 1
PrintBigLabels.Print()
End Sub
Private Sub PrintSmLabels_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintSmLabels.PrintPage
e.Graphics.DrawString(SKUTextBox.Text, SKUTextBox.Font, Brushes.Black, 20, 12)
e.Graphics.DrawString(SKULabel.Text, SKULabel.Font, Brushes.Black, 0, 12)
e.Graphics.DrawString(VTextBox.Text, VTextBox.Font, Brushes.Black, 82, 12)
e.Graphics.DrawString(VLabel.Text, VLabel.Font, Brushes.Black, 68, 12)
e.Graphics.DrawString(MfgTextBox.Text, MfgTextBox.Font, Brushes.Black, 20, 24)
e.Graphics.DrawString(MfgLabel.Text, MfgLabel.Font, Brushes.Black, 0, 24)
e.Graphics.DrawString(DescTextBox.Text, DescTextBox.Font, Brushes.Black, 0, 38)
e.Graphics.DrawString(MSRPTextBox.Text, MSRPTextBox.Font, Brushes.Black, 0, 66)
e.Graphics.DrawString(MSRPLabel.Text, MSRPLabel.Font, Brushes.Black, 0, 56)
e.Graphics.DrawString(PriceTextBox.Text, PriceTextBox.Font, Brushes.Black, 65, 66)
e.Graphics.DrawString(PriceLabel.Text, PriceLabel.Font, Brushes.Black, 65, 56)
e.Graphics.DrawString(SmBarcode.Text, SmBarcode.Font, Brushes.Black, 3, 85)
e.Graphics.DrawString(SKUTextBox2.Text, SKUTextBox2.Font, Brushes.Black, 39, 104)
End Sub
Private Sub PrintBigLabels_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintBigLabels.PrintPage
e.Graphics.DrawString(BSKUTextBox.Text, BSKUTextBox.Font, Brushes.Black, 45, 2)
e.Graphics.DrawString(BSKULabel.Text, BSKULabel.Font, Brushes.Black, 14, 2)
e.Graphics.DrawString(BVTextBox.Text, BVTextBox.Font, Brushes.Black, 150, 2)
e.Graphics.DrawString(BVLabel.Text, BVLabel.Font, Brushes.Black, 130, 2)
e.Graphics.DrawString(BMfgTextBox.Text, BMfgTextBox.Font, Brushes.Black, 45, 15)
e.Graphics.DrawString(BMfgLabel.Text, BMfgLabel.Font, Brushes.Black, 14, 15)
e.Graphics.DrawString(BDescTextBox.Text, BDescTextBox.Font, Brushes.Black, 14, 28)
e.Graphics.DrawString(BMSRPTextBox.Text, BMSRPTextBox.Font, Brushes.Black, 34, 52)
e.Graphics.DrawString(BMSRPLabel.Text, BMSRPLabel.Font, Brushes.Black, 34, 43)
e.Graphics.DrawString(BPriceTextBox.Text, BPriceTextBox.Font, Brushes.Black, 130, 52)
e.Graphics.DrawString(BPriceLabel.Text, BPriceLabel.Font, Brushes.Black, 130, 43)
e.Graphics.DrawString(BigBarcode.Text, BigBarcode.Font, Brushes.Black, 30, 75)
e.Graphics.DrawString(BSKUTextBox2.Text, BSKUTextBox2.Font, Brushes.Black, 80, 104)
End Sub
End Class[/code]
Also, here is what my data source looks like:<br/>
<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/218110
Any thoughts?
View the full article
I have a form that connects to an Access database via a Dataset.<br/>
I have a form containing a listbox. This listbox is filled by a column in Table2, so it contains over 100 items.<br/>
When a user runs the program and selects a single listbox item, it should filter Table1 so that only the records matching the selection exist.
Table1 has multiple fields that will need to be printed. They are:
Store (Number)<br/>
SKU (Number)<br/>
Vendor_Name (Text)<br/>
Vendor_VSN (Text)<br/>
SKU_Desc (Text)<br/>
MSRP (Currency)<br/>
Price (Currency)<br/>
Change (Number)<br/>
Section (Number)<br/>
Row (Number)<br/>
Quantity (Number)
I have created textboxes associated with these fields. I would like them to be populated by my listbox selection. Here is what I have so far, but I am not sure if I am missing something with the query, or how I should write the code for the textbox to retrieve
data from my source:
<pre class="prettyprint lang-vb Option Strict On
Option Explicit On
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
StoreManagement.Show()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.StoresTableAdapter3.Fill(Me.JDADS.Stores)
Me.JDATableAdapter1.Fill(Me.JDADS.JDA)
Dim storeNums = From dr As JDADS.StoresRow In JDADS.Stores _
Select dr.StoreNum Distinct Order By StoreNum
For Each storeNum As Double In storeNums
ListBox1.Items.Add(storeNum.ToString)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ListBox1.SelectedIndexChanged
Dim lst As List(Of JDADS.JDARow)
If Not Integer.TryParse(ListBox1.Items(ListBox1.SelectedIndex).ToString, 1) Then
Console.WriteLine(ListBox1.SelectedItem.ToString)
Throw New Exception("Something Went Wrong!")
Else
Dim qry = From dr As JDADS.JDARow In JDADS.JDA _
Where dr.store = CInt(ListBox1.Items(ListBox1.SelectedIndex).ToString)
lst = qry.ToList
End If
set value to textbox or smt else from the first row of result.
....
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
PrintSmLabels.PrinterSettings.Copies = 1
PrintSmLabels.Print()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
PrintBigLabels.PrinterSettings.Copies = 1
PrintBigLabels.Print()
End Sub
Private Sub PrintSmLabels_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintSmLabels.PrintPage
e.Graphics.DrawString(SKUTextBox.Text, SKUTextBox.Font, Brushes.Black, 20, 12)
e.Graphics.DrawString(SKULabel.Text, SKULabel.Font, Brushes.Black, 0, 12)
e.Graphics.DrawString(VTextBox.Text, VTextBox.Font, Brushes.Black, 82, 12)
e.Graphics.DrawString(VLabel.Text, VLabel.Font, Brushes.Black, 68, 12)
e.Graphics.DrawString(MfgTextBox.Text, MfgTextBox.Font, Brushes.Black, 20, 24)
e.Graphics.DrawString(MfgLabel.Text, MfgLabel.Font, Brushes.Black, 0, 24)
e.Graphics.DrawString(DescTextBox.Text, DescTextBox.Font, Brushes.Black, 0, 38)
e.Graphics.DrawString(MSRPTextBox.Text, MSRPTextBox.Font, Brushes.Black, 0, 66)
e.Graphics.DrawString(MSRPLabel.Text, MSRPLabel.Font, Brushes.Black, 0, 56)
e.Graphics.DrawString(PriceTextBox.Text, PriceTextBox.Font, Brushes.Black, 65, 66)
e.Graphics.DrawString(PriceLabel.Text, PriceLabel.Font, Brushes.Black, 65, 56)
e.Graphics.DrawString(SmBarcode.Text, SmBarcode.Font, Brushes.Black, 3, 85)
e.Graphics.DrawString(SKUTextBox2.Text, SKUTextBox2.Font, Brushes.Black, 39, 104)
End Sub
Private Sub PrintBigLabels_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintBigLabels.PrintPage
e.Graphics.DrawString(BSKUTextBox.Text, BSKUTextBox.Font, Brushes.Black, 45, 2)
e.Graphics.DrawString(BSKULabel.Text, BSKULabel.Font, Brushes.Black, 14, 2)
e.Graphics.DrawString(BVTextBox.Text, BVTextBox.Font, Brushes.Black, 150, 2)
e.Graphics.DrawString(BVLabel.Text, BVLabel.Font, Brushes.Black, 130, 2)
e.Graphics.DrawString(BMfgTextBox.Text, BMfgTextBox.Font, Brushes.Black, 45, 15)
e.Graphics.DrawString(BMfgLabel.Text, BMfgLabel.Font, Brushes.Black, 14, 15)
e.Graphics.DrawString(BDescTextBox.Text, BDescTextBox.Font, Brushes.Black, 14, 28)
e.Graphics.DrawString(BMSRPTextBox.Text, BMSRPTextBox.Font, Brushes.Black, 34, 52)
e.Graphics.DrawString(BMSRPLabel.Text, BMSRPLabel.Font, Brushes.Black, 34, 43)
e.Graphics.DrawString(BPriceTextBox.Text, BPriceTextBox.Font, Brushes.Black, 130, 52)
e.Graphics.DrawString(BPriceLabel.Text, BPriceLabel.Font, Brushes.Black, 130, 43)
e.Graphics.DrawString(BigBarcode.Text, BigBarcode.Font, Brushes.Black, 30, 75)
e.Graphics.DrawString(BSKUTextBox2.Text, BSKUTextBox2.Font, Brushes.Black, 80, 104)
End Sub
End Class[/code]
Also, here is what my data source looks like:<br/>
<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/218110
Any thoughts?
View the full article