을 폼에 새로운 정보를 입력 한 후, 목록보기에 정보를 업데이트 할, 자신의 메소드를 호출하려고합니다. 예를 들어 이벤트를 사용할 수 있습니다. DataContentChanged
또는 양식에 새 데이터를 추가하는 버튼을 클릭하면 업데이트 방법을 호출 할 수 있습니다. 새로 고침 방법의 예는 다음과 같아야합니다
공공 무효 lbRefresh()를
{
//create itemsList for listbox
ArrayList itemsList = new ArrayList();
//count how many information you wana to add
//here I count how many columns I have in dataGrid1
int count = dataGrid1.Columns.Count;
//for cycle to add my strings of columns headers into an itemsList
for (int i = 0; i < count; i++)
{
itemsList.Add(dataGrid1.Columns[i].Header.ToString());
}
//simply refresh my itemsList into my listBox1
listBox1.ItemsSource = itemsList;
}
< \ 코드>
I가 발생할 경우는 미스 이해 죄송합니다, 도움이되기를 바랍니다.
편집 : 완료하여 문제를 해결하려면,이 코드 조각을 사용하려고 :
//some btn_Click Event in one window //(lets say, its your callback " to update" button in datagrid) private void Button_Click_1(object sender, RoutedEventArgs e) { //here you doing somethin //after your datagrid got updated, try to store the object, //which u want to send into your eg. listbox data[0] = data; //my stored data in array //for better understanding, this method "Button_Click_1" is called from Window1.xaml.cs //and I want to pass information into my another window Graph1.xaml.cs //create "newWindow" object onto your another window and send "data" by constuctor var newWindow = new Graph1(data); //line * //you can call this if u want to show that window after changes applied newWindow.Show(); }
당신의 Graph1.xaml 그 후.CS는 다음과 같이 표시되어야합니다.
public partial class Graph1 : Window
{//this method takes over your data u sent by line * into previous method explained
public Graph1(int[]data)
{
InitializeComponent();
//now you can direcly use your "data" or can call another method and pass your data into it
ownListBoxUpdateMethod(data);
}
private void ownListBoxUpdateMethod(int[] data)
{
//update your listbox here and its done ;-)
}
나는 그것이 도움이되기를 바랍니다. 감사합니다, Kevin Sky.
이벤트를 듣고 있습니까? 이 모호한 질문 (코드 없음)을 사용하면 여기서 많은 도움을 얻지 못할 것입니다. – Najzero
이벤트 listeting에 의해 추측 ... – user1669713