Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

D&D Cursor problem for text box

$
0
0

HI,

I'm using D&D functionality from list view to text boxes,the problem is that when you drop the value from the list view

to the text box the cursor is stay in the last text box which you drop to it value and you cannot change the cursor

to other text box ,how can I avoid it and able to navigate between the text boxes.


The code for the text box events is as follows:


        private void DropText_PreviewDrop(object sender, DragEventArgs e)
        {
            var textbox = (TextBox)sender;
            if (!(textbox.Text.Length > 0))
            {
                var data = e.Data as DataObject;
                if (data != null)
                {
                    var user = data.GetData(typeof(User)) as User;
                    textbox.Tag = user;

                    if (user != null)
                    {
                        string name = user.Name;
                        textbox.Text += name;
                        textbox.Focus();
                        textbox.CaretIndex = textbox.Text.Length;
                        if (!_mapping.ContainsKey(textbox.Name))
                            _mapping.Add(textbox.Name, name);
                        e.Handled = true;
                    }
                }
            }
            else
            {
                e.Handled = true;
            }
        }

       
        private void DropText_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var textBox = (TextBox)sender;
            if (textBox == null) return;
            var dataObject = new DataObject((textBox).Text);
            dataObject.SetData(DragSource, sender);
            DragDrop.DoDragDrop(textBox, dataObject, DragDropEffects.Copy | DragDropEffects.Move);
        }

Thanks ,

Miley



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>