Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

More c# headaches : ListView

  • 01-11-2004 03:53PM
    #1
    Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭


    There are days when I really think I shoudl give up IT and take up something less technical like street-sweeping.....

    Anyway...maybe someone can help me here...

    I have two listviews. Both are essentially defined identically. Both are used with View=Detail only

    In each case, I want to "auto-select" the correct item when loading data to edit. So you can see this when the listview doesn't have the focus I have both listViews changed so that HideSelection = false.

    Because they can't be data-bound, when populating them I actually store the data-object for each ListViewItem in the .Tag property. When selecting the row, I iterate through all ListViewItem objects, and when I find the correct one I select that row. Thusly:
        private void SelectFieldInListView(ListView source, Field fieldToSelect) {
          foreach (ListViewItem lvi in source.Items) {
            if (fieldToSelect.FieldName == ((Field) lvi.Tag).FieldName) {
              lvi.Selected = true;
              break;
            }
          }
        }
    

    One *one* of the listboxes, this works perfectly. On the other, it finds the match, but the .Selected call doesn't work at all. On the one which works, calling the .Selected=true line fires the SelectionChanged event. On the other, it doesn't.

    I've had a quick looky, and I can find *nothing* about a bug which might cause this. I've deleted and re-created the controls. I've stepped line-by-line through the code in case something weird was happening. Nought.

    Has anyone seen/heard of anything like this before?

    Alternately, is there anything (other than a grid) easily available that I can use to simulate a listview in detail mode?


Comments

  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    N'mind.

    As with oh-so-many of these problems, it turned out that Visual Studio corrupting my files somehow was the problem....as when I cut the code, deleted and recreated the control, and pasted teh code back in (for the Nth time) it worked fine.

    jc


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Seems to be a common problem of late. What version of VS or you using? I only ask out of interest.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    I'm using VS-2003 Architect Edition with .Net 1.1, SP1.

    Couple of bits n pieces installed which effect it (e.g. ActiveReports, csUnit), but I've seen these problems outside the environment.

    I'm just hoping that 2005 is a typical "3rd release" from MS, in that they typically start getting things right on release 3.

    jc


Advertisement