Thread: ListView problem

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    132

    ListView problem

    Okay when I call the ListView_GetSubItemRect() it returns the co-ordinates, however, my co-ords are not correct. Using the RECT that is filled by the ListView_GetSubItemRect() call I am creating an editbox (supposed to be created at the location and be the size of the subitem I used during that call) for user input. However, when the editbox is created it is created in a manner that it is about 10 - 15px above where it should be (for location) and if the subitem happens to be (0,0) in the ListView then it's length is created matching the length of the ListView, however, if the item is (0,1) or otherwise, then it is created with the right length to match the column.

    Can anyone help me with this issue?

    Here is some code:

    Code:
    // get ready for user input
    err = ListView_GetSubItemRect(expHwnds.hLV_Wnd, 0, 0, LVIR_BOUNDS, &rect);
    if( err == 0 )
    {
    	sprintf(error, "Unable to get dimensions of first item. %u", GetLastError());
    	MessageBox(NULL, error, "Error", MB_ICONEXCLAMATION);
    	return(-1);
    }
    else
    {
    	expHwnds.hEdit = CreateWindow("EDIT", "MM/DD/YYYY", WS_CHILD | WS_BORDER | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, hwnd, NULL, g_hInst, NULL);
    	if( expHwnds.hEdit == NULL )
    	{
    		sprintf(error, "Unable to initialize user input for Expense module. (Error 0027; %u)", GetLastError());
    		MessageBox(NULL, error, "Error", MB_ICONEXCLAMATION);
    		return(-1);
    	}
    }
    I'm not sure exactly why this is happening. Probably something very simple and stupid (maybe I should try sleep to remedy my problems? lol let me know, maybe that would be a solution!)

    Tyouk

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Assumably, ListView_GetSubItemRect is returning a rectangle that is relative to its client rectangle. However, you are positioning the edit control relative to the parent window. You need to take into account the offset from the parent client rectangle to the list-view client rectangle.

    As a simpler alternative have you considered the LVS_EDITLABELS style?
    Quote Originally Posted by MSDN List-view Styles
    LVS_EDITLABELS
    Item text can be edited in place. The parent window must process the LVN_ENDLABELEDIT notification message. It can also handle the LVN_BEGINLABELEDIT notification message.
    P.S. Very wide code makes your post and your code hard to read. Consider breaking up lines that are too long to be viewed without scrolling.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    132
    Yes I have created the ListView using the LVS_EDITLABELS style, however, that style hinders your access to actually edit the information in the ListView. You can only edit the first item, and I want the entire ListView editable.

    Thanks for the help though, now that I fixed the relativity of the RECT being returned, I was able to get it in the right location.

    Tyouk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ListView Refresh, Update
    By de4th in forum C++ Programming
    Replies: 1
    Last Post: 12-23-2006, 09:13 AM
  2. ListView & ImageLists
    By @nthony in forum Windows Programming
    Replies: 2
    Last Post: 07-16-2006, 04:44 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. Troubles with ListView and Toolbar
    By cornholio in forum Windows Programming
    Replies: 8
    Last Post: 11-14-2005, 01:26 AM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM