How to: Create a Custom Search Panel
- 2 minutes to read
This example demonstrates how to implement a custom search panel. Do this as follows:
- Create an InformationLayer object and assign it to the InformationLayer.DataProvider property. Specify the object’s BingMapDataProviderBase.BingKey property. Note that the built-in search panel is not used in this example, so the object’s BingSearchDataProvider.ShowSearchPanel property is set to false.
- Build a custom search panel. In this example, the search panel includes two text edits (for keyword and location) and the Search button.
- Call the BingSearchDataProvider.Search method in the Search button click event handler.
Note
Refer to How to: Get a Bing Maps Key if you run the application and see a window with the following error message: “The specified Bing Maps key is invalid. To create a developer account, refer to https://www.microsoft.com/en-us/maps/create-a-bing-maps-key“.
using System;
using System.Windows.Forms;
using DevExpress.XtraMap;
namespace MapControl_SearchPanel {
public partial class Form1 : Form {
InformationLayer SearchLayer { get { return (InformationLayer)mapControl1.Layers["SearchLayer"]; } }
BingSearchDataProvider SearchProvider { get { return (BingSearchDataProvider)SearchLayer.DataProvider; } }
public Form1() {
InitializeComponent();
SearchLayer.DataRequestCompleted += SearchLayer_DataRequestCompleted;
}
void SearchLayer_DataRequestCompleted(object sender, RequestCompletedEventArgs e) {
mapControl1.ZoomToFitLayerItems();
}
private void bSearch_Click(object sender, EventArgs e) {
SearchProvider.Search(teKeyword.Text);
}
}
}