Name
속성이 있고 ToString()
속성을 다시 사용하여 ListBoxItem
을 만들었습니다. 그것은 새로운 항목을 추가 할 때 멋지게 작동합니다.ListBox에서 항목 업데이트 강제 적용
하지만 이제는 선박 이름을 변경할 때 ListBox
에 라벨을 업데이트해야합니다. 새로 고침이나 업데이트로 그렇게 할 수 있다고 생각했지만 작동하지 않습니다.
나는 여기에서 아주 쉽게 뭔가를 놓칠 수 있습니다.
public class ShipListBoxItem
{
public ListBox Parent { get; set; }
public ShipType Ship { get; set; }
public ShipListBoxItem()
{
Ship = new ShipType();
}
public ShipListBoxItem(ShipType st)
{
Ship = st;
}
public override string ToString()
{
return Ship.Name;
}
public void UpdateListBox()
{
Parent.Refresh(); //My problem is here. Update doesn't work either.
}
public static ShipListBoxItem AddToListBox(ListBox lb, ShipType ship)
{
ShipListBoxItem li = new ShipListBoxItem(ship);
li.Parent = lb;
lb.Items.Add(li);
return li;
}
}
과 같은 OnSelectedIndexChanged을 트리거합니다. 추가 된 항목을 표시하려면 새로 고칠 필요가 없습니다. 나는 이것을 다음과 같이 불렀다 : ShipType s1 = new ShipType(); s1.Name = textBox1.Text; ShipListBoxItem.AddToListBox (this.listBox1, s1); – NoChance
수정하지 않고 항목을 추가해도 문제가 없습니다. – user2888973
UpdateListBox()는 인수를 사용하지 않고 어떻게 업데이트합니까? – NoChance