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 1017963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:47:08+00:00 2026-05-16T10:47:08+00:00

I have a WPF combobox <ComboBox Name=cmbExpression IsEditable=True/> Now I have written some text

  • 0

I have a WPF combobox

<ComboBox Name="cmbExpression" IsEditable="True"/> 

Now I have written some text over there say fx(a,b,c) ,f(x),x,p,mv,P#,Fx(X),x,sometext

Now my requirement is that, whenever the cursor or the mouse (arrow keys viz -> and <-) will be placed on the characters, I should be able to get the value.

Some Test cases:

Case 1:

User put the cursor or mouse pointer on x of f(x).

Output will be f(x).

Case 2:

User put on v of mv

Output: mv

Case 3:

User put the cursor on t of sometext.

Output: sometext

Case 4:

User put the cursor on ( on Fx(X)

Output: Fx(X)

Case 5:

    User put the cursor on ',' of  fx(a,b,c) 

   Output: fx(a,b,c)

I am using C#3.0 and WPF

Help needed.

Thanks

  • 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-16T10:47:09+00:00Added an answer on May 16, 2026 at 10:47 am

    TextBox has a method called GetCharacterIndexFromPoint which returns the character index at the supplied position, TextBlock has a similar method which returns a TextPointer. You can use these methods to find the what is under the cursor.

    <ComboBox IsEditable="True" MouseMove="ComboBox_MouseMove" />
    

    Code

    private void ComboBox_MouseMove(object sender, MouseEventArgs e)
    {
        var combobox = (ComboBox)sender;
        //An editable ComboBox uses a TextBox named PART_EditableTextBox 
        var textbox = (TextBox)combobox.Template.FindName("PART_EditableTextBox", combobox);
    
        var pos = textbox.GetCharacterIndexFromPoint(e.GetPosition(textbox),true);
        var text = textbox.Text;
        if (string.IsNullOrEmpty(text))
            return;
    
        txt.Text = GetWordAtPos(text,pos);
    }
    
    private static string GetWordAtPos(string str, int pos)
    {
        Stack<char> matches = new Stack<char>();
        int wordStart = 0, wordEnd = 0;
        for (int i = 0; i < str.Length - 1 && wordEnd == 0; i++)
        {
            char c = str[i];
    
            switch (c)
            {
                case ',':
                    if (matches.Count == 0)
                    {
                        if (i > pos)
                            wordEnd = i;
                        else
                            wordStart = i;
                    }
                    break;
                case '(':
                    matches.Push(')');
                    break;
                case ')':
                    if (matches.Count == 0 || matches.Peek() != c)
                        throw new ArgumentException("Found ) without matching ( character.");
                    else
                        matches.Pop();
                    break;
            }
        }
    
        string word;
        if (wordEnd == 0)
            word = str.Substring(wordStart);
        else
            word = str.Substring(wordStart, wordEnd - wordStart);
    
        return word.Trim(',');
    }
    

    A different approach you may want to look into if you need more control over the appearance of each token would be to generate a Run element for each token, but this seems to work well for the cases you described.

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

Sidebar

Related Questions

I have a combobox in WPF like this: <ComboBox Text=Select Language... IsEditable=True IsReadOnly=True ItemsSource={Binding
I had implemented a wpf combobox into a winform and now have to somehow
I have a ComboBox in WPF which is databound, and has data template which
I have a WPF application in VS 2008 with some web service references. For
I have a WPF toolkit DataGrid as the dropdown in a ComboBox template. <toolkit:DataGrid
I have a list of custom objects: say Fruits with two string properties Name
I want to have a wpf combobox that displays the dropdown list box with
I have a WPF UserControl that contains a ComboBox . I need to attach
I have a combobox on a window in wpf and i am trying to
I'm currently working on a WPF UI and I have a combobox on my

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.