2012-03-30 18 views
3

C#ウィザードコントロールには、ウィザードの手順を進めると起動されるActiveStepChangedというイベントがあります。現在のステップは、ActiveStepIndexというプロパティに格納されます。現在のActiveStepIndexの直前のステップを取得する必要があります。コンポーネントウィザードの最後のステップを取得

私はこの方法を試したが、今までの成果なしだ:

ICollection s = wizTransferSheet.GetHistory(); 
IList steps = s as IList; 
WizardStep lastStep = steps[steps.Count].Name; 

答えて

4

あなたのウィザードでは、時にはトリッキーなことができるよう、どのように複雑な依存。 ActiveStepIndexは必ずしも使用できません。幸いにも、ウィザードコントロールは、訪問した手順の歴史を記録し、あなたが訪れた最後のステップを取得するために、これを活用することができます

あなたが訪れた最後のステップを取得するには、この機能を使用することができます。

/// <summary> 
/// Gets the last wizard step visited. 
/// </summary> 
/// <returns></returns> 
private WizardStep GetLastStepVisited() 
{ 
    //initialize a wizard step and default it to null 
    WizardStep previousStep = null; 

    //get the wizard navigation history and set the previous step to the first item 
    var wizardHistoryList = (ArrayList)wzServiceOrder.GetHistory(); 
    if (wizardHistoryList.Count > 0) 
     previousStep = (WizardStep)wizardHistoryList[0]; 

    //return the previous step 
    return previousStep; 
} 

ここに、ウィザードのサンプルコードがあります。ウィザードはかなり複雑で、ユーザーの操作に基づいて分岐が発生する可能性があります。その分岐のために、ウィザードをナビゲートすることは難しいことです。私はあなたにこれが役に立つかどうかは分かりませんが、もしそうならばそれを含めて価値があると思いました。

/// <summary> 
/// Navigates the wizard to the appropriate step depending on certain conditions. 
/// </summary> 
/// <param name="currentStep">The active wizard step.</param> 
private void NavigateToNextStep(WizardStepBase currentStep) 
{ 
    //get the wizard navigation history and cast the collection as an array list 
    var wizardHistoryList = (ArrayList)wzServiceOrder.GetHistory(); 

    if (wizardHistoryList.Count > 0) 
    { 
     var previousStep = wizardHistoryList[0] as WizardStep; 
     if (previousStep != null) 
     { 
      //determine which direction the wizard is moving so we can navigate to the correct step 
      var stepForward = wzServiceOrder.WizardSteps.IndexOf(previousStep) < wzServiceOrder.WizardSteps.IndexOf(currentStep); 

      if (currentStep == wsViewRecentWorkOrders) 
      { 
       //if there are no work orders for this site then skip the recent work orders step 
       if (grdWorkOrders.Items.Count == 0) 
        wzServiceOrder.MoveTo(stepForward ? wsServiceDetail : wsSiteInformation); 
      } 
      else if (currentStep == wsExtensionDates) 
      { 
       //if no work order is selected then bypass the extension setup step 
       if (grdWorkOrders.SelectedItems.Count == 0) 
        wzServiceOrder.MoveTo(stepForward ? wsServiceDetail : wsViewRecentWorkOrders); 
      } 
      else if (currentStep == wsSchedule) 
      { 
       //if a work order is selected then bypass the scheduling step 
       if (grdWorkOrders.SelectedItems.Count > 0) 
        wzServiceOrder.MoveTo(stepForward ? wsServicePreview : wsServiceDetail); 
      } 
     } 
    } 
} 
関連する問題