We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to load intellisense popup with different collections based on keywords in WinForms SyntaxEditor (EditControl)?

Platform: WinForms |
Control: EditControl |
Published Date: August 13, 2018 |
Last Revised Date: December 11, 2019 |
.NET Framework: 4

Load intellisence popup

As like in Microsoft Visual Studio Code Editor, EditControl has support for Intellisence Popup and helps end users to configure own Key combination to display the Intellisence Popup . The ContextChoice events will be helpful in this scenario.

 

For example

In this example, we are explaining this configuration capability of EditControl to open with different collection based on display Keywords. i.e. tables keyword to display tables collection and function keyword to display function collection.

 

The following code demonstrates the same.

C#

// Ensure that the context choice popup is displayed if the invoking lexems are "function" or "tables" only
private void editControl1_ContextChoiceBeforeOpen(object sender, System.ComponentModel.CancelEventArgs e)
{
 ILexem lex;
 ILexemLine lexemLine = this.editControl1.GetLine(this.editControl1.CurrentLine);
 //Gets the index of the current word in that line
 int ind = GetContextChoiceCharIndex(lexemLine);
 if (ind<=0)
 {
  e.Cancel = true;
  return;
 }
 lex = lexemLine.LineLexems[ind-1] as ILexem;
 // If the count is less than '2', do not show the ContextChoice popup
 if (lexemLine.LineLexems.Count<2)
  e.Cancel = true;
 else
 {
  // Display ContextChoice popup if the lexem used to invoke them is "function" or "tables" only
  //Check if current line text is "function" or "tables"
  if ((lex.Text == "function") || (lex.Text == "tables"))
    //Open Context Choice list
    e.Cancel = false;
  else
  {
    //Cancel request
    e.Cancel = true;
  }
 }
}
// Populate the context choice list on popup
private void 
editControl1_ContextChoiceOpen(Syncfusion.Windows.Forms.Edit.Interfaces.IContextChoiceController controller)
{
  ILexem lex;
  ILexemLine lexemLine = this.editControl1.GetLine(this.editControl1.CurrentLine);
  //Gets the index of the current word in that line
  int ind = GetContextChoiceCharIndex(lexemLine);
  if (ind <= 0)
  {
    return;
  }
  lex = lexemLine.LineLexems[ind - 1] as ILexem;
  if (lexemLine.LineLexems.Count < 2)
    return;
  else
  {
    // Display ContextChoice popup if the lexem used to invoke them is "function" or "tables" only
    //Add Context choice list for "function" word
    if (lex.Text == "function")
    {
      controller.Items.Add("Function 1", "This is Function 1",    this.editControl1.ContextChoiceController.Images["Image0"]);
      controller.Items.Add("Function 2", "This is Function 2", this.editControl1.ContextChoiceController.Images["Image1"]);
      controller.Items.Add("Function 3", "This is Function 3", this.editControl1.ContextChoiceController.Images["Image2"]);
      controller.Items.Add("Function 4", "This is Function 4", this.editControl1.ContextChoiceController.Images["Image3"]);
    }
    //Add context choice list for "tables" word
    else if(lex.Text == "tables")
    {
      controller.Items.Add("Table 1", "This is Table 1", this.editControl1.ContextChoiceController.Images["Image0"]);
      controller.Items.Add("Table 2", "This is Table 2", this.editControl1.ContextChoiceController.Images["Image1"]);
      controller.Items.Add("Table 3", "This is Table 3", this.editControl1.ContextChoiceController.Images["Image2"]);
      controller.Items.Add("Table 4", "This is Table 4", this.editControl1.ContextChoiceController.Images["Image3"]);
    }
  }
}
 
 

 

 

Code Example: [VB]

 

' Ensure that the context choice popup is displayed if the invoking lexems are "function" or "tables" only
Private Sub editControl1_ContextChoiceBeforeOpen(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles editControl1.ContextChoiceBeforeOpen
   Dim lex As ILexem
   Dim lexemLine As ILexemLine = Me.editControl1.GetLine(Me.editControl1.CurrentLine)
   'Gets the index of the current word in that line
   Dim ind As Integer = GetContextChoiceCharIndex(lexemLine)
   If ind<=0 Then
     e.Cancel = True
   Return
   End If
   lex = TryCast(lexemLine.LineLexems(ind-1), ILexem)
   ' If the count is less than '2', do not show the ContextChoice popup
   If lexemLine.LineLexems.Count<2 Then
      e.Cancel = True
   Else
      ' Display ContextChoice popup if the lexem used to invoke them is "function" or "tables" only
   If (lex.Text = "function") OrElse (lex.Text = "tables") Then
      e.Cancel = False
   Else
      e.Cancel = True
   End If
  End If
End Sub
 
' Populate the context choice list on popup
Private Sub editControl1_ContextChoiceOpen(ByVal controller As 
Syncfusion.Windows.Forms.Edit.Interfaces.IContextChoiceController) Handles 
editControl1.ContextChoiceOpen
   Dim lex As ILexem
   Dim lexemLine As ILexemLine = Me.editControl1.GetLine(Me.editControl1.CurrentLine)
   'Gets the index of the current word in that line
   Dim ind As Integer = GetContextChoiceCharIndex(lexemLine)
   If ind <= 0 Then
     Return
   End If
   lex = TryCast(lexemLine.LineLexems(ind - 1), ILexem)
   If lexemLine.LineLexems.Count < 2 Then
     Return
   Else
     'Display ContextChoice popup if the lexem used to invoke them is "function” or "tables" only
     'Add Context choice list for "function" word
     If lex.Text = "function" Then
       controller.Items.Add("Function 1", "This is Function 1", 
Me.editControl1.ContextChoiceController.Images("Image0"))
       controller.Items.Add("Function 2", "This is Function 2", 
Me.editControl1.ContextChoiceController.Images("Image1"))
       controller.Items.Add("Function 3", "This is Function 3", 
Me.editControl1.ContextChoiceController.Images("Image2"))
       controller.Items.Add("Function 4", "This is Function 4", 
Me.editControl1.ContextChoiceController.Images("Image3"))
       'Add Context choice list for "tables" word
     ElseIf lex.Text = "tables" Then
       controller.Items.Add("Table 1", "This is Table 1", 
Me.editControl1.ContextChoiceController.Images("Image0"))
       controller.Items.Add("Table 2", "This is Table 2",  Me.editControl1.ContextChoiceController.Images("Image1"))
       controller.Items.Add("Table 3", "This is Table 3", Me.editControl1.ContextChoiceController.Images("Image2"))
       controller.Items.Add("Table 4", "This is Table 4", Me.editControl1.ContextChoiceController.Images("Image3"))
     End If
   End If
End Sub

 

Screenshot

context choice popup open for after entering function word

Figure: ContextChoice popup open for after entering “function” word.

 

context choice popup open for after entering table word

Figure: ContextChoice popup open for after entering “tables.” word

 

Samples:

C#:  EditControl_ContextChoice

VB:  EditControl_ContextChoice

 

Reference link: https://help.syncfusion.com/windowsforms/syntax-editor/intellisense

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Uy Suy
Oct 26, 2020

Where can I find function GetContextChoiceCharIndex(lexemLine)?

Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile