R
Ron Bullman
Gerald,
Very long question indeed. I'm assuming that your listBox1 is
System.Windows.Forms.ListBox, then you can access the selected item from C#
like this listBox1.Items[listBox1.SelectedIndex]
Ron
Very long question indeed. I'm assuming that your listBox1 is
System.Windows.Forms.ListBox, then you can access the selected item from C#
like this listBox1.Items[listBox1.SelectedIndex]
Ron
Gerald Lightsey said:I am doing some work that involves automating MS MapPoint 2002. The
object model is documented in the context of Visual Basic 6.0. A
typical example follows.
'Output first result of find search
Set objFindResults = objApp.ActiveMap.FindAddressResults("One Microsoft
Way", "Redmond", , "WA", , geoCountryUnitedStates)
MsgBox "The first item in the find list is: " _
+ objFindResults.Item(1).Name
FindResults is a collection. In C# I find that the VB6 syntax .Item (1)
is not acceptable nor is [1]. I don't know if it is acceptable in
VB.NET or not.
When MapPoint attempts to locate an input address it returns an
assessment of how well the results in the specified FindResult
collection match the input criteria, (e.g. geoFirstResultGood,
geoAmbiguousResults, geoNoGoodResult). Therefore if a complete and
unambiguous address is input the ResultsQuality property will be
geoFirstResultGood, and I can .
IEnumerator frEnumerator = oFindResults.GetEnumerator();
frEnumerator.MoveNext();
locX = (MapPoint.Location) frEnumerator.Current;
listBox1.Items.Add( locX.Name );
listBox1.SetSelected(0, true );
If one of the other ResultsQuality values is returned I can.
foreach (MapPoint.Location locX in oFindResults)
{
listBox1.Items.Add( locX.Name );
}
If such an address is simply missing a North/South qualifier there will
only be two or three entries in the listBox. On the other hand, If the
address is 100 N Main St, Willburg, MA, 010907 where someone has
misspelled the city name and the Post Office has changed the zip code,
there can be several hundred items listed in listBox1 showing every 100
Main, City and Zip in Massachusetts. I have no problem with the time
required to LOAD the listBox. At this point I want to manually select
from listBox1 the location on which to perform further MapPoint
operations.
The only way I have been able to do this in C# has been to find the
index of the selected item in the listBox and then walk through the
collection AGAIN to reach the location object on which to perform the
further operations.
if ( listBox1.SelectedIndex != -1 )
{
IEnumerator frEnumerator = oFindResults.GetEnumerator();
for ( int stepper = 0; stepper <= listBox1.SelectedIndex; stepper++ )
frEnumerator.MoveNext();
thisLocation = (MapPoint.Location) frEnumerator.Current;
}
For the list containing several hundred items, walking the collection
again takes a perceptible amount of time on a fast CPU. It seems that
when I know the index of the item in the listBox I should be able to go
directly to the item in the collection rather than walking the
collection again. Is there a better way in C# that I have not found?
Gerald