using a combobox.selecteditem

  • Thread starter Thread starter Peted
  • Start date Start date
P

Peted

So i have this code

private void PopulateProblemPage()
{
List<ListItem> problemPageList = new List<ListItem>();
foreach (PCSProblemPageType problem in
_billingEventData.ProblemPageList)
{
ListItem problemItem = new
ListItem(problem.ID.ToString(), problem.DisplayTerm, null);
problemPageList.Add(problemItem);
}

cboProblemPage.DataSource = problemPageList;



}

where the combobox cboProblemPage is populated with a list.

im having trouble, with how do i use the combobox.SelectedItem
property to make a specific item in the list the currently selected
one in the combobox

should this not work

ListItem probToMakeCurrent = new ListItem(problem.ID.ToString(),
problem.DisplayTerm, null);


cboProblemPage.SelectedItem = probToMakeCurrent ;


assuming probToMakeCurrent matches an item in the list assigned to
the combobox, is this not the way to do it ?


any advice appreciiated

Peted
 
Peted said:
So i have this code

private void PopulateProblemPage()
{
List<ListItem> problemPageList = new List<ListItem>();
foreach (PCSProblemPageType problem in
_billingEventData.ProblemPageList)
{
ListItem problemItem = new
ListItem(problem.ID.ToString(), problem.DisplayTerm, null);
problemPageList.Add(problemItem);
}

cboProblemPage.DataSource = problemPageList;



}

where the combobox cboProblemPage is populated with a list.

im having trouble, with how do i use the combobox.SelectedItem
property to make a specific item in the list the currently selected
one in the combobox

should this not work

ListItem probToMakeCurrent = new ListItem(problem.ID.ToString(),
problem.DisplayTerm, null);


cboProblemPage.SelectedItem = probToMakeCurrent ;


assuming probToMakeCurrent matches an item in the list assigned to
the combobox, is this not the way to do it ?


any advice appreciiated

Peted

Hi Peted,

Hard to say as the ListItem class you are using does not appear to be a
Framework type object. No constructor overload supports three parameters
with the last parameter being nullable. It may well be that you need to
reference the exact ListItem reference from the list. You appear to be in a
windows environment, so make sure you aren't calling the method from a form
constructor or similar, but wait till at least the Load event has started.
 
Back
Top