Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

something like Ctype? or Overloading or Inheritance maybe? 1

Status
Not open for further replies.

HerbAndEdnaWeinstein

Technical User
Joined
Apr 30, 2003
Messages
104
Location
US
Hi,

I've got a function that uses a DataGrid and a DataSet.

Here it is:

***********************************************
Private Function FindMap(ByVal cpX As Integer, ByVal cpY As Integer, ByVal datagridx As DataGrid, ByVal datasetx As DataSet) As String

blahblahblah

End Function
************************************************

I've got another bit of code that calls the function, and its intended purpose is to parse the proper DataGrid and DataSet name into the function. Here's what it looks like:

************************************************
blahblahblah

dim datagridy as string
dim datasety as string
dim foundmap as string

datagridy = "Datagrid_" & am
datasety = "Dataset_" & am & "1"
foundmap = FindMap(cpX, cpY, datagridy, datasety)

blahblahblah
************************************************

This does not work, because it says that a "String" cannot be converted to type "DataSet" or type "DataGrid". I also tried Ctype()ing datagridy and datasety into DataGrid and Dataset, and of course that didn't work.

So, what's the best, easiest way do get the program to "Do What I Mean?"

Thanks for any ideas!!
Herb
 
This should do the trick for you. It loops through the controls on your form looking for the one you want and then calls your function. This is just making up a name in the form load and then calling the function. "Me" represents the form (container) you are on.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim mydatagrid As String = "Datagrid"
Dim mydatagridNumber As String = "1"

Dim FullString As String = mydatagrid & mydatagridNumber

FindControl(Me.Controls, FullString)

End Sub
Private Sub FindControl(ByVal contin As Control.ControlCollection, ByVal ControlName As String)

Dim foundcontrol As Control

'this will loop through all the controls to find the one with the correct name
For Each foundcontrol In contin
If foundcontrol.Name = "DataGrid1" Then
FindMap(foundcontrol)
End If

'This is needed in case the control is on a panel or something
If foundcontrol.Controls.Count <> 0 Then
FindControl(foundcontrol.Controls, ControlName)
End If
Next foundcontrol

End Sub

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
DotNetDoc:

That works like a charm on the DataGrid part, thanks! Now all I have to do is figure out how to do the same with the Dataset.

It says that DataSet is not a collection type.

Any other ideas?
Herb
 
What does FindMap do with the dataset?

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
FindMap refers to Table(0) within a specified DataSet, and does a search within the Table.
 
FWIW, here's the entirety of FindMap. cpX and cpY are the X,Y coordinates of a mouse click.

***********************************************************
Private Function FindMap(ByVal cpX As Integer, ByVal cpY As Integer, ByVal datagridx As DataGrid, ByVal datasetx As DataSet) As String

Dim k, l, maxX, maxY, minX, minY As Integer

For k = 0 To datasetx.Tables(0).Rows.Count - 2

minX = CType(datagridx.Item(k, 1), Integer)
maxX = CType(datagridx.Item(k, 3), Integer)
minY = CType(datagridx.Item(k, 2), Integer)
maxY = CType(datagridx.Item(k, 4), Integer)

If cpX >= minX And cpX < maxX Then
If cpY >= minY And cpY < maxY Then
FindMap = (datagridx.Item(k, 0))
End If
End If
Next k

End Function
***********************************************************

Thanks again,
Herb
 
I am assuming you have more than one dataset? Is this correct?


DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
Yes, there are lots of datasets now, and users may need to spontaneously add more later...

rs
 
As you create datasets you can add them to a hash table

Then you can access them using the key like below. But make sure you really need to create many datasets. Can you just create datatables in a single dataset?

Dim FullString As String = mydatagrid & mydatagridNumber
Dim FullString2 As String = myDataset & myDatasetNumber


Dim DataSet1 As DataSet
Dim DataSet2 As DataSet
Dim DataSet3 As DataSet

Dim myHT As New Hashtable
myHT.Add(&quot;DataSet1&quot;, DataSet1)'String is the Key, then the object
myHT.Add(&quot;DataSet2&quot;, DataSet2)
myHT.Add(&quot;DataSet3&quot;, DataSet3)

Dim DataSetx As DataSet = myHT(&quot;DataSet1&quot;)

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
Thanks, the hashtable did the trick all the way across the board. it's the sort of text-parsing &quot;swiss army knife&quot; i was looking for :)

I just added:

***********************************************************
findhash.Add(&quot;DataSet_400CityGrid1&quot;, DataSet_400CityGrid1)
findhash.Add(&quot;DataSet_400MapGrid1&quot;, DataSet_400MapGrid1)
findhash.Add(&quot;DataGrid_400CityGrid&quot;, DataGrid_400CityGrid)
findhash.Add(&quot;DataGrid_400MapGrid&quot;, DataGrid_400MapGrid)
***********************************************************

Then I called:

***********************************************************
foundmap = FindMap(cpX, cpY, findhash(datagridy), findhash(datasety))
***********************************************************





Herb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top