Autocompletebox auto height

4 posts, 0 answers
  1. Ivan
    Ivan avatar
    2 posts
    Member since:
    Sep 2013

    Posted 21 Jan Link to this post

    Hello,

    I am new to Telerik, so maybe there was an answer to this subject, but couldn't find it. So what I need is auto height of autocompletebox. So when new box is set to new line, I want the whole control to change height, up to maximum 4 lines (then vertical scrollbar shoud show up). But also if I delete some of the boxes, the control should lower it's height.

     I tried with

    private void VScrollBar_ValueChanged(object sender, EventArgs e)
            {
                this.radAutoCompleteBox1.TextBoxElement.VScrollBar.Value = 0;
                this.radAutoCompleteBox1.Size = new Size(this.radAutoCompleteBox1.Size.Width, this.radAutoCompleteBox1.Size.Height + 10);
            }

    but it can only increase height, but cannot decrease height. I also tried to get number of lines, but it is always 0.

    Thanks
    Ivan

  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 22 Jan Link to this post

    Hi Ivan,

    Thank you for writing.

    You can subscribe to the TextChanged event and adjust the height acording to the current lines count:
    public RadForm1()
    {
        InitializeComponent();
        for (int i = 0; i < 10; i++)
        {
            radAutoCompleteBox1.AutoCompleteItems.Add("Item " + i);
        }
        radAutoCompleteBox1.Multiline = true;
        radAutoCompleteBox1.AcceptsReturn = true;
     
        radAutoCompleteBox1.TextChanged += radAutoCompleteBox2_TextChanged;
    }
     
    int tokenHeight = 18;
     
    void radAutoCompleteBox2_TextChanged(object sender, EventArgs e)
    {
        if (radAutoCompleteBox1.Lines.Length > 0 && radAutoCompleteBox1.Lines.Length < 4)
        {
           radAutoCompleteBox1.Height = (tokenHeight + radAutoCompleteBox1.Margin.Vertical) * radAutoCompleteBox1.Lines.Length  ;
           Console.WriteLine(radAutoCompleteBox1.Lines.Length);
        }
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        radAutoCompleteBox1.Height = 300;
    }

    I hope this helps.

    Regards,
    Dimitar
    Telerik

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ivan
    Ivan avatar
    2 posts
    Member since:
    Sep 2013

    Posted 22 Jan in reply to Dimitar Link to this post

    Dimitar,

    Thanks, I already tried this. The main problem is that if I don't click Enter, the Line number is 0. So what if user in e-mail client add 50 addresses, but he never click Enter, just use Space between two entries (I always do it in Outlook, not 50, but 10 addresses). Your control displays second line, but line number is still 0, since it is one row of text. Is there any other way ??

     One more question, how to programaticaly add text in autocompletebox, but also add value, or change value when I add text ? If i try radAutoCompleteBox1.Items there is no Add option. And if I try to change Value in radAutoCompleteBox1_CreateTextBlock(object sender, Telerik.WinControls.UI.CreateTextBlockEventArgs e) Value property is ReadOnly. Do I miss something here, or there is no way to add value programaticaly ?

    Thank
    Ivan

  5. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 26 Jan Link to this post

    Hello Ivan,

    Thank you for writing back.

    You can set the AutoSize property to true and then specify minimum and maximum size:
    radAutoCompleteBox1.AutoSize = true;
    radAutoCompleteBox1.MinimumSize = new Size(200, 26);
    radAutoCompleteBox1.MaximumSize = new Size(200, 0);

    You can add a value by setting the Text property. More information is available here: Text Editing.

    Let me know if I can assist you further.

    Regards,
    Dimitar
    Telerik

Back to Top