ComboBox에는 사용하도록 설정해야하는 항목과 사용하지 않도록 설정해야하는 항목이 있습니다. 제 콤보 ItemsSource에서조건을 만족하는 ComboBox 항목을 프로그래밍 방식으로 사용하지 않도록 설정하는 방법
설정되어 comboBoxMachine가 ComboBox
이다
comboBoxMachine.ItemsSource = machineList;
및 machineList는이 List<Machine>
리스트가 갖는 각 기계
후에 조건 (Machine
맞춤 목적) 인 확인하고 ComboBox에서 해당 항목을 사용하지 않도록 설정해야합니다. 다음은
private void modifyMachineComboBoxItems()
{
foreach (Machine mch in machineList)
{
if (constructionSiteSchedule.ReservationMachinePeriods.Count(x => x.MachineId == mch.Id) > 0) //if this condition is fulfilled, it should be not possible to select the machine from the comboBoxMachine
{
int currentPosition = machineList.IndexOf(mch);
disable the element from the comboBoxMachine at position currentPosition;
}
}
}
지금까지 알아 낸 나는 매우 감사 할 것입니다 수 있도록 지정된 위치에있는 콤보 상자에서 요소를 사용하지 않도록 설정하는 방법입니다하지 않은 무엇 위의 코드를 수정하여 조건을 만족하는 컴퓨터의 ComboBox 항목을 사용할 수 없게하는 경우
이미 여기에 대한 답이 비슷한 것 같다 : http://stackoverflow.com/questions/1003318/wpf-how-to-disable-combobox-items –
목록에서 항목을 삭제할 수 없습니까? 그렇지 않으면 ComboBoxItem을 확장하고 비활성화 상태로 설정할 수 있어야합니다. –
이렇게 하시겠습니까? 그게 좋은 UI 디자인인지 확신 할 수 없기 때문입니다. – svick