locked
Datagridview Multiline Textbox With Autocomplete Source RRS feed

  • Question

  • So I have come to learn the Autocomplete is not supported when a textbox's word wrap property is set to true. Now with my code I have the Datagridview.EditingControlShowing setting my current cell as a textbox so i can add an auto complete source to it. However without word wrap the text is cut by the end of the box. I do not wish to re-size the columns. So I was hoping somebody might be able to offer me a work around. I have tried many different posts with solutions for multiline text with word wrap, working with auto complete, but because I am working with a datagridview none have proven helpful to me.

    I am working off a MySQL database just for the record.

    Thanks for any help in advance!

    Tuesday, January 5, 2016 11:42 PM

Answers

  • Hello,

    There is no solution via the standard TextBox with AutoComplete as we can see in the first if statement from TextBox source. If you want auto complete this would need to be a custom solution which I don't have.

    internal void SetAutoComplete(bool reset)
    {
        if ((!this.Multiline && (this.passwordChar == '\0')) && (!this.useSystemPasswordChar && (this.AutoCompleteSource != System.Windows.Forms.AutoCompleteSource.None)))
        {
            if (this.AutoCompleteMode != System.Windows.Forms.AutoCompleteMode.None)
            {
                if (!this.fromHandleCreate)
                {
                    System.Windows.Forms.AutoCompleteMode autoCompleteMode = this.AutoCompleteMode;
                    this.autoCompleteMode = System.Windows.Forms.AutoCompleteMode.None;
                    base.RecreateHandle();
                    this.autoCompleteMode = autoCompleteMode;
                }
                if (this.AutoCompleteSource == System.Windows.Forms.AutoCompleteSource.CustomSource)
                {
                    if (base.IsHandleCreated && (this.AutoCompleteCustomSource != null))
                    {
                        if (this.AutoCompleteCustomSource.Count == 0)
                        {
                            this.ResetAutoComplete(true);
                        }
                        else if (this.stringSource != null)
                        {
                            this.stringSource.RefreshList(this.GetStringsForAutoComplete());
                        }
                        else
                        {
                            this.stringSource = new StringSource(this.GetStringsForAutoComplete());
                            if (!this.stringSource.Bind(new HandleRef(this, base.Handle), (int) this.AutoCompleteMode))
                            {
                                throw new ArgumentException(System.Windows.Forms.SR.GetString("AutoCompleteFailure"));
                            }
                        }
                    }
                }
                else
                {
                    try
                    {
                        if (base.IsHandleCreated)
                        {
                            int num = 0;
                            if (this.AutoCompleteMode == System.Windows.Forms.AutoCompleteMode.Suggest)
                            {
                                num |= -1879048192;
                            }
                            if (this.AutoCompleteMode == System.Windows.Forms.AutoCompleteMode.Append)
                            {
                                num |= 0x60000000;
                            }
                            if (this.AutoCompleteMode == System.Windows.Forms.AutoCompleteMode.SuggestAppend)
                            {
                                num |= 0x10000000;
                                num |= 0x40000000;
                            }
                            System.Windows.Forms.SafeNativeMethods.SHAutoComplete(new HandleRef(this, base.Handle), ((int) this.AutoCompleteSource) | num);
                        }
                    }
                    catch (SecurityException)
                    {
                    }
                }
            }
            else if (reset)
            {
                this.ResetAutoComplete(true);
            }
        }
    }
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter or Facebook via my MSDN profile but will not answer coding question on either.

    Wednesday, January 6, 2016 1:58 AM

All replies

  • Hello,

    There is no solution via the standard TextBox with AutoComplete as we can see in the first if statement from TextBox source. If you want auto complete this would need to be a custom solution which I don't have.

    internal void SetAutoComplete(bool reset)
    {
        if ((!this.Multiline && (this.passwordChar == '\0')) && (!this.useSystemPasswordChar && (this.AutoCompleteSource != System.Windows.Forms.AutoCompleteSource.None)))
        {
            if (this.AutoCompleteMode != System.Windows.Forms.AutoCompleteMode.None)
            {
                if (!this.fromHandleCreate)
                {
                    System.Windows.Forms.AutoCompleteMode autoCompleteMode = this.AutoCompleteMode;
                    this.autoCompleteMode = System.Windows.Forms.AutoCompleteMode.None;
                    base.RecreateHandle();
                    this.autoCompleteMode = autoCompleteMode;
                }
                if (this.AutoCompleteSource == System.Windows.Forms.AutoCompleteSource.CustomSource)
                {
                    if (base.IsHandleCreated && (this.AutoCompleteCustomSource != null))
                    {
                        if (this.AutoCompleteCustomSource.Count == 0)
                        {
                            this.ResetAutoComplete(true);
                        }
                        else if (this.stringSource != null)
                        {
                            this.stringSource.RefreshList(this.GetStringsForAutoComplete());
                        }
                        else
                        {
                            this.stringSource = new StringSource(this.GetStringsForAutoComplete());
                            if (!this.stringSource.Bind(new HandleRef(this, base.Handle), (int) this.AutoCompleteMode))
                            {
                                throw new ArgumentException(System.Windows.Forms.SR.GetString("AutoCompleteFailure"));
                            }
                        }
                    }
                }
                else
                {
                    try
                    {
                        if (base.IsHandleCreated)
                        {
                            int num = 0;
                            if (this.AutoCompleteMode == System.Windows.Forms.AutoCompleteMode.Suggest)
                            {
                                num |= -1879048192;
                            }
                            if (this.AutoCompleteMode == System.Windows.Forms.AutoCompleteMode.Append)
                            {
                                num |= 0x60000000;
                            }
                            if (this.AutoCompleteMode == System.Windows.Forms.AutoCompleteMode.SuggestAppend)
                            {
                                num |= 0x10000000;
                                num |= 0x40000000;
                            }
                            System.Windows.Forms.SafeNativeMethods.SHAutoComplete(new HandleRef(this, base.Handle), ((int) this.AutoCompleteSource) | num);
                        }
                    }
                    catch (SecurityException)
                    {
                    }
                }
            }
            else if (reset)
            {
                this.ResetAutoComplete(true);
            }
        }
    }
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter or Facebook via my MSDN profile but will not answer coding question on either.

    Wednesday, January 6, 2016 1:58 AM
  • Hello,

    There is no solution via the standard TextBox with AutoComplete as we can see in the first if statement from TextBox source. If you want auto complete this would need to be a custom solution which I don't have.

    internal void SetAutoComplete(bool reset)
    {
        if ((!this.Multiline && (this.passwordChar == '\0')) && (!this.useSystemPasswordChar && (this.AutoCompleteSource != System.Windows.Forms.AutoCompleteSource.None)))
        {
            if (this.AutoCompleteMode != System.Windows.Forms.AutoCompleteMode.None)
            {
                if (!this.fromHandleCreate)
                {
                    System.Windows.Forms.AutoCompleteMode autoCompleteMode = this.AutoCompleteMode;
                    this.autoCompleteMode = System.Windows.Forms.AutoCompleteMode.None;
                    base.RecreateHandle();
                    this.autoCompleteMode = autoCompleteMode;
                }
                if (this.AutoCompleteSource == System.Windows.Forms.AutoCompleteSource.CustomSource)
                {
                    if (base.IsHandleCreated && (this.AutoCompleteCustomSource != null))
                    {
                        if (this.AutoCompleteCustomSource.Count == 0)
                        {
                            this.ResetAutoComplete(true);
                        }
                        else if (this.stringSource != null)
                        {
                            this.stringSource.RefreshList(this.GetStringsForAutoComplete());
                        }
                        else
                        {
                            this.stringSource = new StringSource(this.GetStringsForAutoComplete());
                            if (!this.stringSource.Bind(new HandleRef(this, base.Handle), (int) this.AutoCompleteMode))
                            {
                                throw new ArgumentException(System.Windows.Forms.SR.GetString("AutoCompleteFailure"));
                            }
                        }
                    }
                }
                else
                {
                    try
                    {
                        if (base.IsHandleCreated)
                        {
                            int num = 0;
                            if (this.AutoCompleteMode == System.Windows.Forms.AutoCompleteMode.Suggest)
                            {
                                num |= -1879048192;
                            }
                            if (this.AutoCompleteMode == System.Windows.Forms.AutoCompleteMode.Append)
                            {
                                num |= 0x60000000;
                            }
                            if (this.AutoCompleteMode == System.Windows.Forms.AutoCompleteMode.SuggestAppend)
                            {
                                num |= 0x10000000;
                                num |= 0x40000000;
                            }
                            System.Windows.Forms.SafeNativeMethods.SHAutoComplete(new HandleRef(this, base.Handle), ((int) this.AutoCompleteSource) | num);
                        }
                    }
                    catch (SecurityException)
                    {
                    }
                }
            }
            else if (reset)
            {
                this.ResetAutoComplete(true);
            }
        }
    }


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter or Facebook via my MSDN profile but will not answer coding question on either.

    You say "If you want auto complete this would need to be a custom solution which I don't have." but then you go on to provide a function of some sort. Im not really sure how this code will help me or how to implement it. Can you please elaborate further on the code you have provided?
    Monday, January 18, 2016 8:03 PM
  • The code I presented is part of the source code within the Framework, nothing I write. In short one would need to create a new TextBox control which inherits from the base TextBox, TextBoxBase which I have not done.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    Monday, January 18, 2016 8:48 PM