Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Create a Custom Search Panel

  • 2 minutes to read

This example implements a custom search panel.

View Example

  1. Create an InformationLayer object and assign it to the InformationLayer.DataProvider property. Specify the object’s BingMapDataProviderBase.BingKey property.

    Note

    This example does not use the built-in search panel, so the MapSearchPanelOptions.Visible property is set to false.

  2. Build a custom search panel. In this example, the search panel includes two text edits (for keyword and location) and a Search button.
  3. Call the BingSearchDataProvider.Search method in the Search button’s 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);
        }
    }
}