2011-09-02 7 views
1

수정 사항을 적용하려고 시도한 후 4 번이 질문을합니다. 내 문제는 내가 하나의 ID를 보유하고 다른 하나는 셀 ID를 보유하고 목록 상자가 있습니다. ID 목록 상자에는 테스트 용 10 개의 항목이 있고 셀 상자에는 5 개의 ID가 있습니다. 나는목록 상자 목록 상자를 통해 루핑하지 않는 문

예를 MakeReq ... 동시에 업데이트 링크를 생성에 listId 및 listcell 요소를 처리하기 위해 노력하고있어

 store.domain.com/101/sec01&ire=1 
     store.domain.com/102/sec02&ire=1 
     store.domain.com/103/sec03&ire=1 
     store.domain.com/104/sec04&ire=1 
     store.domain.com/105/sec05&ire=1 
     store.domain.com/106/sec01&ire=1 <- notice how listCell starts over it 
continues to loop applying sections until the ListID is complete. 
txtWebUpdate.Text listID은 listcell & 분노 = 1을 만듭니다

여기에 내가 작업해온 코드가 있습니다. 내 코드에서 일어나는 일은 첫 번째 항목 만 선택한다는 것입니다. 완료 후 다음 항목으로 이동하지 않습니다.

 if (listId.Items.Count != 0 && listCell.Items.Count != 0) 
     { 
      for (int a = 0; a < listId.Items.Count; a++) 
      { 
       for (int b = 0; b < listCell.Items.Count; b++) 
       { 
        lblID.Text = listId.Items[a].ToString(); 
        MakeReq(txtWebUpdate.Text + listId.Items[a].ToString() + 
         "&ire=1", listCell.Items[b].ToString()); 
        //System.Threading.Thread.Sleep(5); 
       } 
      } 
     } 

도움이 될 경우 의견을주십시오. 문제는 for 문이고 목록 항목을 선택하는 방법은 거의 긍정적이지만 잘못된 것일 수 있습니다.

편집 더 많은 정보 : @duffp에 대한 예제/제안을 테스트 한 후이 문제 아래에 분명히 For 문이 있습니다. 무슨 일이 일어나고있는 건 ListCell에 5 개의 항목이 있고 그 중 하나 (같은) ListID를 5 회했지만 다른 ListCell로 출력한다는 것입니다. 누군가 내가 위의 잘못에 따라 쓰도록 도울 수 있습니까?

+0

목록 상자를 업데이트하면 다시 게시가 트리거되어 루프에서 벗어나게됩니까? –

+0

@kcsavage 예. 나는 vb6에서 이것과 비슷한 것을하기 위해 잠시 동안 사용합니다. VB에서 Remove 속성을 사용하여 각 프로세스가 끝나면 항목을 제거합니다. 그래서 항상 첫 번째 항목을 잡을 것입니다. 하지만이 경우 ListCell 중 하나에서 두 개의 목록 상자를 사용하여 작업하고 있는데 목록 셀은 각 ListID에 대해 SecID를 제공하는 연속 루프가 필요하기 때문에 항목을 제거 할 수 없습니다. – acctman

답변

0

MakeReq 메서드 호출 내에서 뭔가 할 수 있습니다. 난 그냥 다음 코드를 시도 :

private void Form1_Load(object sender, EventArgs e) 
    { 

     if (listId.Items.Count != 0 && listCell.Items.Count != 0) 
     { 
      for (int a = 0; a < listId.Items.Count; a++) 
      { 
       for (int b = 0; b < listCell.Items.Count; b++) 
       { 
        lblID.Text = listId.Items[a].ToString(); 
        MakeReq(listId.Items[a].ToString(), listCell.Items[b].ToString()); 

       } 
      } 
     }    
    } 
    public void MakeReq(string listId, string cellId) 
    { 
     Console.WriteLine("store.domain.com/" + listId + "sec01&ire=" + cellId); 
    } 

을 그리고 출력했다 :

store.domain.com/ID_10sec01&ire=Cell_1 
store.domain.com/ID_10sec01&ire=Cell_2 
store.domain.com/ID_10sec01&ire=Cell_3 
store.domain.com/ID_10sec01&ire=Cell_4 
store.domain.com/ID_10sec01&ire=Cell_5 
store.domain.com/ID_10sec01&ire=Cell_6 
store.domain.com/ID_10sec01&ire=Cell_7 
store.domain.com/ID_10sec01&ire=Cell_8 
store.domain.com/ID_10sec01&ire=Cell_9 
store.domain.com/ID_10sec01&ire=Cell_10 

가 당신이 원하는 것을되지 않습니다?

+0

store.domain.com/ID_01 sec 01 & ire = 1 store. domain.com/ListID + ListCell ... 예 :/01sec01 & ire = 1 ListCell이 끝나면/11sec01 & ire = 1 이상으로 시작됩니다. 모든 listCell은 루프에서 섹션을 적용하는 동안 ListID가 위에서 아래로 한 번에 똑같이 처리됩니다. – acctman

+0

ID_10이있는 ID는 항상 다릅니다. 최상위 출력 결과보기 store.domain.com/101/sec01&ire=1 101 ListID sec01 is listCell ... ListID가 106이되면 ListCell이 시작됩니다. 왜냐하면 ListCell에는 5 개의 항목 만 있기 때문입니다. listID 상자가 완료 될 때까지 다시 시작해야하더라도 secID (listCell)를 계속 적용합니다. – acctman

0

MakeReq에는 우리에게 표시되지 않는 부작용이있을 수 있습니다. 어떻게이 같은 코드에 일부 디버그 문을 추가하는 방법에 대해 : 뭔가 listCell.Items을 변경하지 않는 한

if (listId.Items.Count != 0 && listCell.Items.Count != 0) 
    { 
     for (int a = 0; a < listId.Items.Count; a++) 
     { 
      int listCellCount = listCell.Items.Count; 
      for (int b = 0; b < listCell.Items.Count; b++) 
      { 
       lblID.Text = listId.Items[a].ToString(); 
       MakeReq(txtWebUpdate.Text + listId.Items[a].ToString() + 
        "&ire=1", listCell.Items[b].ToString()); 
       //System.Threading.Thread.Sleep(5); 
       Debug.Assert(listCellCount == listCell.Items.Count); 
      } 
     } 
    } 

단언 (listCellCount == listCell.Items.Count)는 항상 진실해야합니다.

+0

나는 그의 예에서 @duffp처럼 console.write를 사용했다. 그리고 제가 눈치 채지 못한 또 다른 문제가 있습니다. 그것은 MakeReq() Console.write 출력 동안 나는 동일한 ListID 인쇄 프로세스 당 10 번 나가고 있어요. 그래서 내 For 문은 모두 잘못되었습니다.그 이유는 내가 그 MakeReq이 아니라 문자열을 들고 이외의 아무것도하지 않기 때문에. 레이블을 대신 사용하면 동일한 정보가 올바른 정보를 출력하지 않게됩니다. – acctman