Back to Devexpress

How to: Create a Custom Search Panel

windowsforms-16767-controls-and-libraries-map-control-examples-gis-data-searching-how-to-create-a-custom-search-panel.md

latest2.7 KB
Original Source

How to: Create a Custom Search Panel

  • Jul 04, 2025
  • 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.

  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.

csharp
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);
        }
    }
}
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraMap

Namespace MapControl_SearchPanel
    Partial Public Class Form1
        Inherits Form

        Private ReadOnly Property SearchLayer() As InformationLayer
            Get
                Return CType(mapControl1.Layers("SearchLayer"), InformationLayer)
            End Get
        End Property
        Private ReadOnly Property SearchProvider() As BingSearchDataProvider
            Get
                Return CType(SearchLayer.DataProvider, BingSearchDataProvider)
            End Get
        End Property

        Public Sub New()
            InitializeComponent()
            AddHandler SearchLayer.DataRequestCompleted, AddressOf SearchLayer_DataRequestCompleted
        End Sub

        Private Sub SearchLayer_DataRequestCompleted(ByVal sender As Object, ByVal e As RequestCompletedEventArgs)
            mapControl1.ZoomToFitLayerItems()
        End Sub

        Private Sub bSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bSearch.Click
            SearchProvider.Search(teKeyword.Text)
        End Sub
    End Class
End Namespace