Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:49:52+00:00 2026-05-25T02:49:52+00:00

I am using following WPF Code <ComboBox Name=cmbFunctionsList Grid.Row=3 Grid.Column=1 DropDownClosed=OnCmbFunctionsListDropDownClosed DisplayMemberPath=FunctionItem SelectedValuePath=FunctionValue PreviewMouseLeftButtonDown=OnFunctionsListPreviewMouseLeftButtonDown

  • 0

I am using following WPF Code

<ComboBox Name="cmbFunctionsList"  Grid.Row="3" Grid.Column="1"  
                      DropDownClosed="OnCmbFunctionsListDropDownClosed"
                      DisplayMemberPath="FunctionItem" SelectedValuePath="FunctionValue" 
                      PreviewMouseLeftButtonDown="OnFunctionsListPreviewMouseLeftButtonDown"
                      PreviewMouseMove="OnFunctionsListPreviewMouseMove"                      
                      MinHeight="25"  Margin="2,2,2,0" VerticalAlignment="Center"/>

<TextBox Grid.Column="1" Margin="2" Grid.Row="2" Grid.ColumnSpan="2" Name="txtExpression"
            AllowDrop="True" Drop="OnTxtExpressionDrop" DragEnter="OnTxtExpressionDragEnter" />





 private void OnFunctionsListPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        //storing the mouse position
        _startPoint = e.GetPosition(null);
    }
private void OnFunctionsListPreviewMouseMove(object sender, MouseEventArgs e)
{

    // Drag and Drop Code is commented
    // Get the current mouse position
    Point mousePos = e.GetPosition(null);
    Vector diff = _startPoint - mousePos;

    if (e.LeftButton == MouseButtonState.Pressed &&
       Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
       Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
    {
        ComboBox cmb = sender as ComboBox;
        cmb.StaysOpenOnEdit = true;

        ComboBoxItem cmbItem = FindAnchestor<ComboBoxItem>((DependencyObject)e.OriginalSource);

        if (cmbItem != null)
        {
            if (cmbFunctionsList.SelectedIndex > -1 && cmbFunctionsList.IsDropDownOpen == true)
            {
                // Find the data behind the ComboBoxItem
                DataRowView dr = (DataRowView)cmb.ItemContainerGenerator.ItemFromContainer(cmbItem);

                string draggedText = (String)dr[1];

                // Initialize the drag & drop operation
                DataObject dragData = new DataObject("stringFormat", draggedText);
                DragDrop.DoDragDrop(cmbItem, dragData, DragDropEffects.Copy);
            } 
        }
    }
}


 private void OnTxtExpressionDragEnter(object sender, DragEventArgs e)
        {

            if (!e.Data.GetDataPresent("stringFormat") || sender == e.Source)
            {
                e.Effects = DragDropEffects.Copy;
            }

        }

  private void OnTxtExpressionDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("stringFormat"))
            {
                String droppedText = e.Data.GetData("stringFormat") as String;
                TextBox txtExp = sender as TextBox;
                txtExp.Text = droppedText;
            }

        }

but still the Drag and drop functionality is not working . Moreover when I try to drag an item from comboBox it is getting closed automatically.

Can you suggest to me what I am missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:49:53+00:00Added an answer on May 25, 2026 at 2:49 am

    Drop event is automatically handled in WPf so need not to write the event Drop or Preview Drop

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if i m using following type of code then SelectionChanged Event of WPF comboBox
I have the following code in a WPF application using Reactive Extensions for .NET:
I'm using the following code in my WPF Project : Task.Factory.StartNew( () => {
The following WPF code gets the error: The name 'zipButtonOut' does not exist in
I'm using the following code to display unhandled exceptions in a WPF application: public
When I display a JPEG in my WPF application (using the following code), it
Using MEF I want to do the following. I have a WPF Shell. To
I am using following PHP code to connect to MS Access database: $odb_conn =
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,
I'm using following peace of code to output an array: echo ======output without array_unique=====;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.