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

Initial selection of ListControl is not shown.

1 Answer 26 Views
ListControl
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 21 Feb 2014, 09:51 PM
I have a RADListControl which requires scrolling in order to see all the items.  After the control is Initialized, I populate it and set the initial selection.  If that selection is beyond the initial visible range of the list, it is selected, but the list is not scrolled to make it visible.  (e.g., if I set SelectedIndex of the control with a list of 100 items to 50, item 50 is selected after the initial draw, but only items 0 through 20 are shown if the control is only tall enough to show 20 items.)

Subsequent changes to the SelectedINdex work as expected - i.e., if I change the selection no an item that id beyond the current visible range of the list, then the list will scroll enough to make it visible.

Is there a way to cause the initial selection to be displayed?  Sample code below.

namespace ListBoxScrollTest
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();

      for (int i = 0; i < 101; i++)
      {
        radListControl1.Items.Add(i.ToString());
      }

      numericUpDown1.Minimum = 0;
      numericUpDown1.Maximum = listBox1.Items.Count - 1;
      numericUpDown1.Value = (int)(listBox1.Items.Count/2);

      int init = (int)(numericUpDown1.Value);
      radListControl1.SelectedIndex = init;
    }

    private void numericUpDown1_ValueChanged(object sender, EventArgs e)
    {
      int val = (int)(numericUpDown1.Value);
      radListControl1.SelectedIndex = val;
    }

  }
}

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 26 Feb 2014, 01:25 PM
Hi Robert,

Thank you for writing.

You can use the ScrollToItem method in order to ensure that the item will be visible:
private void Form1_Load(object sender, EventArgs e)
{
    radListControl2.ScrollToItem(radListControl2.Items[50]);
}

Let me know if you have additional questions.

Regards,
Dimitar
Telerik
Tags
ListControl
Asked by
Robert
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or