473,770 Members | 4,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing position of ListViewItem

I've been searching the newsgroup for an answer but probably with the wrong
keywords...

Imagine that I have a ListView with some items and the listview view is
Details. How do I move an item up or down the list?

Cheers

Padu
Aug 3 '06 #1
6 5025
Padu <pa**@merlotti. comwrote:
I've been searching the newsgroup for an answer but probably with the wrong
keywords...

Imagine that I have a ListView with some items and the listview view is
Details. How do I move an item up or down the list?
Hmm ... I haven't tried it, but can't you just remove and reinsert items in
the ListView.Items collection?

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20 .en/CPref17/html/T_System_Window s_Forms_ListVie w_ListViewItemC ollection_Membe rs.htm
--
>
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
Aug 3 '06 #2

"Thomas T. Veldhouse"
>I've been searching the newsgroup for an answer but probably with the
wrong
keywords...

Imagine that I have a ListView with some items and the listview view is
Details. How do I move an item up or down the list?

Hmm ... I haven't tried it, but can't you just remove and reinsert items
in
the ListView.Items collection?
I thought about that, but it seemed too cumbersome and counterintuitiv e at
that time. I thought that the problem was soo obvious and I was surely
missing something. I there's not a more elegant solution, I'll do that.

Cheers and thanks

Padu
Aug 3 '06 #3
According to the Help,
ListViewItem has an Index property.
See if this helps you.
Roger
Imagine that I have a ListView with some items and the listview view is
Details. How do I move an item up or down the list?

Cheers

Padu


Aug 3 '06 #4

public int Index { get; }
Aug 4 '06 #5
"Roger"
>
public int Index { get; }

That's how I do in other languages (aka Delphi). In Delphi, the ItemIndex
property is read/write, in C# it is read only (as you posted above). I'm
starting to think that there's no other way than deleting the item and
re-inserting at the position you want... I expected more.

Cheers

Padu
Aug 4 '06 #6
"Padu"
I've been searching the newsgroup for an answer but probably with the
wrong keywords...

Imagine that I have a ListView with some items and the listview view is
Details. How do I move an item up or down the list?

Cheers

Padu
Ok, that's how I've done it:
private void mniEditUp_Click (object sender, EventArgs e)
{
if (!AreThereSelec tedItems()) return;

//we want to insert one position above, if not the first one
if (SelectedItem() .Index 0)
{
int idx = SelectedItem(). Index - 1;
ListViewItem item = (ListViewItem)S electedItem().C lone();

SelectedItem(). Remove();

ListViewItem inserted = lvwCommands.Ite ms.Insert(idx, item);
inserted.Select ed = true;
inserted.Focuse d = true;

RefreshListEdit GUICommands();
}
}
I don't know if it's the best way to do it, but it works...
Cheers

Padu
Aug 4 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6666
by: Max Adams | last post by:
ListView - changing the text of subitem n? All, How can I change the text of a specific subitem of a specific ListViewItem? I want to have some "Status" column which I want to continually update based on the progress of the program. Thanks PT
2
4279
by: John Smith | last post by:
Hey folks, I've got a combobox (DropDown List) in a windows form application which is bound to a DataSet. It's value is set to a numeric ID. It's visible text is set to a date. I need to make it so that the first item shows the words "Most Recent" instead of the date. I've tried setting the SelectedItem, Text, and SelectedText of the list box to "Most Recent", when the SelectedIndex changes to 0, but nothing happens.
6
13103
by: grs | last post by:
The following is a code example from the Microsoft MSDN. My question is on the following three lines of code: ListViewItem item1 = new ListViewItem("item1",0); ListViewItem item2 = new ListViewItem("item2",1); ListViewItem item3 = new ListViewItem("item3",0); You would in most cases know the ListViewItem name or the number of items to create (item1,item2 etc). How would you create this individual rows programmatically ?
0
1050
by: Filippo Bettinaglio | last post by:
Hi, I use VS2005 , C#, .net2.0 framework. I need to be able to position where I want the Items inside a listview. I tried the belowed code but the items are always align togheter i turn off also AutoArrange but it doesn't work.
1
5244
by: plmanikandan | last post by:
Hi, I have a listview with items,subitems.I tems and subitems are added as below listView1.View = View.Details; listView1.Columns.Add("Column 1", 100,HorizontalAlignment.Center); listView1.Columns.Add("Column 2", 100,HorizontalAlignment.Center); listView1.Columns.Add("Column 3", 100,HorizontalAlignment.Center); listView1.Columns.Add("Column 4", 100,HorizontalAlignment.Center); System.Windows.Forms.ListViewItem itmp = new
0
1603
by: garyusenet | last post by:
I am trying to create a form that will display a list of open internet explorer windows and allow the user to choose one of them. So far I have created an arraylist which contains all of the open internet explorer windows. In the for() part of the code below I have tried to create a listviewitem for each window of internet explorer open (i.e. each element of the arraylist). However it's not working. I don't seem to have access to IE's...
10
3529
by: Gav | last post by:
I am trying to have a ListView to dispay a list of names and want to have an id stored within the list but not visable. I have tried to go about doing this by using the ListViewItem and setting the Text and Tag properties. Problem is when I add the ListViewItem to the ListView I get the following ListViewItem: {Test1} ListViewItem: {Test2} ListViewItem: {Test3}
0
2009
by: svx | last post by:
Hello, I am painting individual rows in a ListView control with different colors, depending on state. I am also using a SmallImageList in Detail view. When I set the SmallImageList.TransparentColor to the correct color, the background color of the image becomes the BackColor of the ListView control itself, instead of the row (ListViewItem) color, which I want. Even within the column containing the image, the rest of the column is...
2
6175
by: witpo | last post by:
Hi, I would like to display all listview items in one row with scroll bar below it – instead of multiple rows and scroll bar on the right. Someone told me that I can achieve it using LVM_SETITEMPOSITION message. According to my knowledge code below should set position for each item added to listView control. There are two ways of doing it - we can use MessageWindow.SendMessage from Microsoft.WindowsCE.Forms or use DllImport and SendMessage....
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.