Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit subitems of a ListView control in C#

Status
Not open for further replies.

polocar

Programmer
Joined
Sep 20, 2004
Messages
89
Location
IT
Hello,
I'm writing in C#, I have a ListView control and I would like to give the user the possibility to edit the subitems' texts.
I have searched in the forum a solution to my question, and I have found a nice idea, that is the creation of a textbox control exactly over the subitem the user has clicked to.
The problem of this technique is that I don't know how to obtain the top, left and height properties of the subitem clicked (I can find the main item using the "GetItemAt" method, but then?)
Do you have an idea on how to do it (or if there's another procedure to edit the subitem's text)?

Thank you
 
Ok, I found a good solution in the CodeProject site:


The idea is this:

1) Use ind = SelectedIndeces[0] to retrieve the index of the item the user has clicked to.

2) Use GetItemRect(ind) to retrieve the delimitation rectangle of the item of index "ind" (the selected one). In this way you get the Top and the Height of the SubItem.

3) Sum the width of the columnheaders until you reach the y of the point (in the mousedown and mouseup events' handlers you get the (x, y) coordinates of the click). That sum (stopping the step before exceeding y) gives the Left, and the width of the next columnheader gives the Width of the SubItem.

Problems can raise if you sort the items or change the columns' order. In the link above there's the code that manages also these cases.
 
Do you have to use a list view? Why not use a data grid? You can bind any collection to the data grid.
If you want to use the list view, open a little dialog when the user double clicks on a row and edit the row data in the dialog (Clean and simple).
 
Do you have to use a list view? Why not use a data grid? You can bind any collection to the data grid.
If you want to use the list view, open a little dialog when the user double clicks on a row and edit the row data in the dialog (Clean and simple).
 
I'll follow your suggestion, thank you Korach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top