This is a migrated thread and some comments may be shown as answers.

Autocompletebox auto height

3 Answers 155 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 21 Jan 2016, 11:58 AM

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

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 22 Jan 2016, 10:46 AM
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

0
Ivan
Top achievements
Rank 1
answered on 22 Jan 2016, 01:48 PM

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

0
Dimitar
Telerik team
answered on 26 Jan 2016, 11:29 AM
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

Tags
AutoCompleteBox
Asked by
Ivan
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Ivan
Top achievements
Rank 1
Share this question
or