Как гарантировать, что вновь добавленный узел в древовидном списке выбран и виден?C#

Место общения программистов C#
Ответить
Anonymous
 Как гарантировать, что вновь добавленный узел в древовидном списке выбран и виден?

Сообщение Anonymous »

Я использую элемент управления BrightIdeasSoftware TreeListView. Когда я добавляю новый узел в список, я хочу, чтобы новый элемент был виден и выбран. Я хочу, чтобы список автоматически прокручивался вниз, чтобы обеспечить его видимость.
Для этого я написал следующую функцию

Код: Выделить всё

public void EnsureNodeIsVisible(object item)
{
// Select the new node
treeListView.SelectedObject = item;

// Refresh the object in the TreeListView
treeListView.RefreshObject(item);

// Ensure the model is visible (this should scroll to it)
treeListView.EnsureModelVisible(item);

// Expand the new node
treeListView.Expand(item);

// Force the TreeListView to scroll to the selected item
var olvItem = treeListView.ModelToItem(item);
if (olvItem != null)
{
treeListView.FocusedItem = olvItem;
olvItem.EnsureVisible();
}

// Alternatively, if the node is at the end, manually scroll to the bottom
int maxIndex = treeListView.Items.Count - 1;
if (treeListView.SelectedIndex == maxIndex)
{
treeListView.EnsureVisible(maxIndex);
}

// Scroll the ListView to the item index to force visibility
treeListView.ScrollToIndex(olvItem.Index);
}

internal static class TreeListViewExtensions
{
public static void ScrollToIndex(this TreeListView treeListView, int index)
{
if (index >= 0 && index < treeListView.Items.Count)
{
treeListView.Items[index].EnsureVisible();
}
}
}
Но список не будет прокручиваться вниз, чтобы убедиться, что новый узел виден и выбран. Что мне здесь не хватает?

Подробнее здесь: https://stackoverflow.com/questions/788 ... nd-visible
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»