Как очистить listbox c
Перейти к содержимому

Как очистить listbox c

  • автор:

Как очистить listbox c

Форумчанин

Регистрация: 05.04.2011

Сообщений: 115

Процедура очистки listbox

Процедура очистки содержимого ListBox, поробовал так

 ListBox1.Items:='';

, не получилось. как очистить компонент

Made In USSR!

Регистрация: 01.09.2010

Сообщений: 3,657

listbox.items.clear;

«. В жизни я встречал друзей и врагов.В жизни много всего перевидал.Солнце тело мое жгло, ветер волосы трепал,но я смысла жизни так и не узнал. »
(c) Юрий Клинских aka «Хой»

Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Процедура slai SQL, базы данных 0 04.10.2010 09:35
как добавить в listbox файлы(пишу с помощью bassplayer)(Listbox+opendialog=play) blackstersl Общие вопросы Delphi 11 09.06.2010 13:23
Пожалуйста, нужна срочная помощь. Как восстановить данные после очистки корзины. FeoKat Свободное общение 3 12.11.2009 01:48
Процедура в процедура в C++ Builder Ecosasha C++ Builder 2 06.06.2009 17:17
Залили принтер краской. Что нужно делать для очистки? Stilet Компьютерное железо 11 07.05.2009 04:08

Статья Как очистить listbox в C#

Небольшая заметка, в которой хочу показать, как очистить listBox. Задача встречается довольно часто и имеет очень простое решение. И так для начала создадим небольшое Windows Forms приложение, после чего поместим на форму: элемент управления listBox и кнопку, при нажатии на которую будет выполняться очистка. Каркас готов и теперь можно добавить несколько любых записей.

27260

Когда Вы добавляете новую запись в listBox, она автоматически попадает в коллекции объектов Items, где хранится на протяжении всего жизненного цикла Вашего приложения. Поэтому, для того чтобы очистить listBox, необходимо просто удалить все элементы, которые содержатся внутри данной коллекции. Например, это можно сделать с помощью метода Clear.

private void button1_Click(object sender, EventArgs e)

27261

  • Доступно обновление: Visual Studio 2013 Update 2 RC
  • Нахождение максимального элемента массива
  • Добавление строки в Excel файл

Как очистить listbox c

Пользователь

Регистрация: 12.04.2018

Сообщений: 19

Очистка listBox.DataSource

Как программно очистить listBox.DataSource?

Регистрация: 22.05.2007

Сообщений: 9,518

listBox.DataSource = null;

Пользователь

Регистрация: 12.04.2018

Сообщений: 19

Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Очистка LIstBox Maray Win Api 1 23.10.2016 15:29
dbgrid и datasource в dll hemn6vyr БД в Delphi 1 30.03.2013 15:59
Не могу связать DBLookupComboBox с DataSource ((( apple66 БД в Delphi 6 31.03.2012 00:58
Использование DataSource stalsoft ASP.NET 1 30.09.2011 09:41
DataSource и ComboBox Dotha БД в Delphi 9 29.10.2009 14:54

List Box. Clear Selected Method

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Unselects all items in the ListBox.

public: void ClearSelected();
public void ClearSelected ();
member this.ClearSelected : unit -> unit
Public Sub ClearSelected ()

Examples

The following code example demonstrates how to use the SelectedIndex property with the TopIndex property to move the currently selected item to the top of the list of items in the display area of the ListBox. The example further demonstrates how to remove items using the RemoveAt method of the System.Windows.Forms.ListBox.ObjectCollection class, and how to clear all item selection using the ClearSelected method. The code first moves the currently selected item in the ListBox to the top of the list. The code then removes all items before the currently selected item and clears all selections in the ListBox. This example requires that a ListBox containing items is added to a form and that an item is currently selected in the ListBox.

private: void RemoveTopItems() < // Determine if the currently selected item in the ListBox // is the item displayed at the top in the ListBox. if ( listBox1->TopIndex != listBox1->SelectedIndex ) // Make the currently selected item the top item in the ListBox. listBox1->TopIndex = listBox1->SelectedIndex; // Remove all items before the top item in the ListBox. for ( int x = (listBox1->SelectedIndex - 1); x >= 0; x-- ) < listBox1->Items->RemoveAt( x ); > // Clear all selections in the ListBox. listBox1->ClearSelected(); > 
private void RemoveTopItems() < // Determine if the currently selected item in the ListBox // is the item displayed at the top in the ListBox. if (listBox1.TopIndex != listBox1.SelectedIndex) // Make the currently selected item the top item in the ListBox. listBox1.TopIndex = listBox1.SelectedIndex; // Remove all items before the top item in the ListBox. for (int x = (listBox1.SelectedIndex -1); x >= 0; x--) < listBox1.Items.RemoveAt(x); >// Clear all selections in the ListBox. listBox1.ClearSelected(); > 
Private Sub RemoveTopItems() ' Determine if the currently selected item in the ListBox ' is the item displayed at the top in the ListBox. If listBox1.TopIndex <> listBox1.SelectedIndex Then ' Make the currently selected item the top item in the ListBox. listBox1.TopIndex = listBox1.SelectedIndex End If ' Remove all items before the top item in the ListBox. Dim x As Integer For x = listBox1.SelectedIndex - 1 To 0 Step -1 listBox1.Items.RemoveAt(x) Next x ' Clear all selections in the ListBox. listBox1.ClearSelected() End Sub 

Remarks

Calling this method is equivalent to setting the SelectedIndex property to negative one (-1). You can use this method to quickly unselect all items in the list.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *