claire_bicknell
Well-known member
- Joined
- Dec 10, 2008
- Messages
- 49
- Programming Experience
- Beginner
I have recently created an interactive map with hotspots to show the different shopping malls around the UK.
Ideally what I would like is to be able to click on a region (manchester) and then have it list all the shops located within that selected centre, in a listbox on another form.
Code so far for form1 (interactive map) is:
And the code for the second form (Stores) which has a listbox is:
I am using a sql server database and would only like to return the names of the stores that are housed within a selected shopping mall (selected by clicking on map).
This is going right over my head guys and I am fairly new to this. Any sample coding or amendments to my existing code would be much appreciated as I have given this hours of thought and am getting nowhere, fast!
Thanks
Ideally what I would like is to be able to click on a region (manchester) and then have it list all the shops located within that selected centre, in a listbox on another form.
Code so far for form1 (interactive map) is:
HTML:
Imports System
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class Form1
Private places As New Dictionary(Of String, Rectangle)
Const strConnection As String = "Data Source=(local);Initial Catalog=ShoppingCentre;Integrated Security=True"
Dim con As New SqlConnection(strConnection)
Dim com As New SqlCommand("Select * from dbo.Centre")
Private Sub LoadPlaces()
places.Add("Manchester", New Rectangle(287, 275, 10, 10))
places.Add("Liverpool", New Rectangle(263, 277, 10, 10))
places.Add("Drake Circus", New Rectangle(184, 422, 10, 10))
places.Add("Portsmouth", New Rectangle(283, 421, 10, 10))
places.Add("London", New Rectangle(314, 400, 10, 10))
places.Add("Bristol", New Rectangle(246, 385, 10, 10))
places.Add("Coventry", New Rectangle(301, 352, 10, 10))
places.Add("Birmingham", New Rectangle(287, 345, 10, 10))
places.Add("Sheffield", New Rectangle(304, 283, 10, 10))
places.Add("Leeds", New Rectangle(301, 263, 10, 10))
places.Add("Newcastle", New Rectangle(312, 226, 10, 10))
places.Add("Belfast", New Rectangle(180, 206, 10, 10))
places.Add("Glasgow", New Rectangle(257, 145, 10, 10))
places.Add("Aberdeen", New Rectangle(323, 95, 10, 10))
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadPlaces()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
For Each hotspot As Rectangle In places.Values
e.Graphics.DrawEllipse(Pens.Red, hotspot)
Next
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
For Each place As String In places.Keys
If places(place).Contains(e.Location) Then
Stores.Show()
Me.Hide()
Exit For
End If
Next
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
Dim current As String = Me.ToolTip1.GetToolTip(Me.PictureBox1)
For Each place As String In places.Keys
If places(place).Contains(e.Location) Then
If current <> place Then
Me.ToolTip1.Show(place, Me.PictureBox1)
Exit For
End If
End If
Next
End Sub
And the code for the second form (Stores) which has a listbox is:
HTML:
Imports System
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class Stores
'Private places As New Dictionary(Of String, Rectangle)
Const strConnection As String = "Data Source=(local);Initial Catalog=ShoppingCentre;Integrated Security=True"
Dim con As New SqlConnection(strConnection)
Dim com As New SqlCommand("Select * from dbo.Shops")
Dim myDataAdapter As New SqlDataAdapter()
Dim myDataSet As New DataSet
Public myDataTable As New DataTable
Private Sub Stores_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myDataAdapter.SelectCommand = com
myDataAdapter.SelectCommand.Connection = con
con.Open()
myDataAdapter.Fill(myDataSet, "dbo.Shops")
myDataTable = myDataSet.Tables("dbo.Shops")
'Return myDataTable
con.Close()
'Dim strSQL As String = "SELECT * FROM CentreStores WHERE CentreID='" & Form1.listbox1.text
Call ListBoxItems()
End Sub
Private Sub ListBoxItems()
con.Open()
Dim maxRowCounter As Integer
Dim intRowCounter As Integer
maxRowCounter = myDataSet.Tables("dbo.Shops").Rows.Count
For intRowCounter = 0 To (maxRowCounter - 1)
ListBox1.Items.Add(myDataTable.Rows(intRowCounter).Item("ShopName"))
Next
con.Close()
End Sub
Private Sub lstProducts_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim con As New SqlConnection(strConnection)
con.Open()
'Dim strLoad_File As String
Dim intRow As Integer
intRow = ListBox1.SelectedIndex
'TextBox2.Text = myDataTable.Rows(intRow).Item("OpeningClosingTimes")
TextBox2.Text = myDataTable.Rows(intRow).Item("Description")
TextBox3.Text = myDataTable.Rows(intRow).Item("Website")
'strLoad_File = myDataTable.Rows(intRow).Item("Picture")
'PictureBox1.Load(IO.Path.Combine(Application.StartupPath, strLoad_File))
con.Close()
'com.Connection = con
End Sub
I am using a sql server database and would only like to return the names of the stores that are housed within a selected shopping mall (selected by clicking on map).
This is going right over my head guys and I am fairly new to this. Any sample coding or amendments to my existing code would be much appreciated as I have given this hours of thought and am getting nowhere, fast!
Thanks