2013-03-29 3 views
1

기본 클래스 외부에서 콤보 상자와 같은 텍스트를 액세스 할 수있는 이유는 궁금합니다. 그러나 나는 그것에 항목을 추가 할 수 없습니다 .. 내 콤보 상자의 수정이 설정되어 액세스 구성 요소 C#

public class ImageManager : mainFrame // Where my components are located { public ImageManager() { } public void getText() { Console.WriteLine(comboBox.Text); //Will perfectly retrieve the text from it } public void setItem() { comboBox.Items.Add("Items"); //Does absolutely nothing and doesn't show error } } 

공공 감사에 도움을!

+0

콤보 상자의 내용을 어떻게 확인합니까? – Steve

+0

내 클래스 mainFrame에서 comboBox.Text = "Test"를 설정 한 다음 ImageManager의 아무 곳에서나 getText()를 호출하면 내 콘솔에 "Test"가 표시됩니다. –

+0

comboBox.Text를 사용하여 텍스트를 가져 오려고하면 무엇을 얻을 수 있습니까? 콤보 박스에 표시됩니다. 항목을 선택하지 않으면 항목을 선택할 때까지 아무것도 얻을 수 없습니다. – hagensoft

답변

1

setItem()ComboboxItem이 채워지고 텍스트 대신 추가되는 경우 어떻게해야합니까?

public void setItem() 
{ 
    ComboboxItem addMe = new ComboboxItem(); 
    addMe.Text = "your text here"; 
    addMe.Value = 1234; // make a relevant value 
    comboBox.Item.Add(addMe); 
} 
+0

완벽하게 작동! –

0

나는 그것을 잘 보았다. 그러나 당신의 머리를 아직도 긁을 경우를 대비하여 ...

ImageManager는 comboBox가있는 Form2에서 상속됩니다. 잘 작동하는 것 같았습니다. comboBox가 채워졌습니다.