Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

More c# headaches : ListView

Options
  • 01-11-2004 3:53pm
    #1
    Registered Users 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 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 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 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