listWidget->Deselect(); PRInt32 selectedIndex = -1; for (PRUint32 i=0; i < mNumOptions; i++) { GetOptionSelected(i, &selected); if (selected) { listWidget->SelectItem(i); selectedIndex = i; } } if (mIsComboBox && (mNumOptions > 0) && (selectedIndex == -1)) { listWidget->SelectItem(0); SetOptionSelected(0, PR_TRUE); }  NS_RELEASE(options); NS_RELEASE(listWidget); if (saveOptionSelected) delete [] saveOptionSelected;
NS_IMETHODIMP nsSelectControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue){  if (nsHTMLAtoms::selected == aName) {    return NS_ERROR_INVALID_ARG; // Selected is readonly according to spec.  } else if (nsHTMLAtoms::selectedindex == aName) {    PRInt32 error = 0;    PRInt32 selectedIndex = aValue.ToInteger(&error, 10); // Get index from aValue    if (error) {      return NS_ERROR_INVALID_ARG; // Couldn't convert to integer    } else {      // Update local cache of selected values      for (PRUint32 i=0; i < mNumOptions; i++)        SetOptionSelected(i, PR_FALSE);      SetOptionSelected(selectedIndex, PR_TRUE);      // Update widget      nsIListWidget* listWidget;      nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget);      if ((NS_OK == result) && (nsnull != listWidget)) {        listWidget->Deselect();        listWidget->SelectItem(selectedIndex);        NS_RELEASE(listWidget);      }    }  } else {    return nsFormControlFrame::SetProperty(aName, aValue);  }  return NS_OK;}