2012-04-16 4 views
0

[あなたが右のいくつかの選択したファイル/フォルダを右クリックして[プロパティ]を選択すると、Windowsのように。]私は
[リストビュー]私の小さなファイルエクスプローラから選択した項目のプロパティフォームを作成しようとしている異なる属性値を持つ複数のファイルがある場合、どのようにチェックボックスの不確定状態を設定するのですか?

フォームが名前を示し、場所、種類、サイズとは、それは[WCFサービス]サーバー・クライアント・アプリケーションですので、私は独自のスレッドで起動マルチと呼ばれる方法で、サーバから属性を取得

属性。

質問があります: [Hidden]と[Readonly]の属性値が異なる複数のファイルがある場合、CheckState.Indeterminateを設定するにはどうすればよいですか。私がしました

private void GetAttributes(FileAttributes fAttributes) 
{ 
    this.Invoke((MethodInvoker)delegate 
    { 
     if (fAttributes != 0) 
     { 
      bool hidden = (fAttributes & FileAttributes.Hidden) == FileAttributes.Hidden; 
      if (Hidden.Checked != hidden) 
       Hidden.CheckState = CheckState.Indeterminate; 
      bool readOnly = (fAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; 
      if (ReadOnly.Checked != readOnly) 
       ReadOnly.CheckState = CheckState.Indeterminate; 
     } 
    }); 
} 

public void Multi() 
{ 
    FileAttributes fAttributes = client.GetAttributeOfPath(item[0].Path) 
    this.Invoke((MethodInvoker)delegate 
    { 
     if (fAttributes != 0) 
     { 
      Hidden.Checked = (fAttributes & FileAttributes.Hidden) == FileAttributes.Hidden; 
      ReadOnly.Checked = (fAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; 
     } 
    }); 
    for (int i = 1; i < itemCollection.Count; i++) 
    { 
     Item item = itemCollection[i]; 
     GetAttributes(client.GetAttributeOfPath(item.Path)); 
    } 
} 

答えて

0

enter image description here

WCF_Client.FM_ServiceReference.FileManagerClient client; 

private void Form_MultiProp_Load(object sender, EventArgs e) 
    { 
     Thread th = new Thread(Multi); 
     th.Start(); 
    } 

private void GetAttributes(FileAttributes fAttributes) 
    { 
     this.Invoke((MethodInvoker)delegate 
     { 
      if (fAttributes != 0) 
      { 
       if ((fAttributes & FileAttributes.Hidden) == FileAttributes.Hidden) 
        Hidden.Checked = true; 
       if ((fAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) 
        ReadOnly.Checked = true; 
      } 
     }); 
    } 

    public void Multi() 
    { 
     foreach (Item item in itemCollection) 
     { 
      GetAttributes(client.GetAttributeOfPath(item.Path)); 
     } 
    } 
+0

私はこのコードがあなたがしたいことをしていると思いますが、非常に複雑な方法で行います。 –

+0

@ david.sまあまあ誰かが私の質問に答えるまで多くの人が思ったので、他の情報も同じループを計算するアプリケーションでうまくいきますが、あなたのやり方は質問の方がいい答えです。 –

0

あなたが別の属性を持つファイルを見つけた場合、その後不定にそれらを設定し、最初のファイルの非表示や読み取り専用のチェックボックスを設定する必要がありますCheckStateがReadonlyCheckBoxとHiddenCheckBoxにあるべきかどうかを決定するCheckingメソッドと呼ばれるすべての属性をリストに追加しましたチェックメソッドprev attribute == next attributeをチェックするCheckState。

List<FileAttributes> listAttributes = new List<FileAttributes>(); 

private void HiddenInvoke(CheckState HiddenState) 
    { 
     this.Invoke((MethodInvoker)delegate 
     { 
      Hidden.CheckState = HiddenState; 
     }); 
    } 
    private void ReadOnlyInvoke(CheckState ReadOnlyState) 
    { 
     this.Invoke((MethodInvoker)delegate 
     { 
      ReadOnly.CheckState = ReadOnlyState; 
     }); 
    } 
    private void HiddenCheck(bool check) 
    { 
     this.Invoke((MethodInvoker)delegate 
     { 
      Hidden.Checked = check; 
     }); 
    } 
    private void ReadOnlyCheck(bool check) 
    { 
     this.Invoke((MethodInvoker)delegate 
     { 
      ReadOnly.Checked = check; 
     }); 
    } 

public void Multi() 
    { 
     try 
     { 
      long SizeAll = 0; 
      int fileCount = 0, folderCount = 0; 
      LocInvoke(Loc); 
      foreach (ListViewItem item in SelectedItems) 
      { 
       // some other calculations.. 
       if (client.IsFile(item.ToolTipText)) 
        TypeInvoke(++fileCount, folderCount); 
       else if (client.IsFolder(item.ToolTipText)) 
        TypeInvoke(fileCount, ++folderCount); 
       // Adding Attributes to a list 
       listAttributes.Add(client.GetAttributeOfPath(item.ToolTipText)); 
       //Size Calculation 
       SizeInvoke(CnvrtUnit(SizeAll += client.GetSizeOfPath(item.ToolTipText))); 
      } 
      Checking(); 
      Finished("OK", true); 
     } 
     catch { } //in case user closes the form before it finishes 
    } 

private void Checking() 
    { 
     bool hiddenSet = false; 
     bool readonlySet = false; 
     for (int i = 1; i < listAttributes.Count; i++) 
     { 
      if (hiddenSet && readonlySet) //checks if they already different then there's no need to check again 
       return; 
      if (!hiddenSet) 
      { 
       if ((listAttributes[i - 1] & FileAttributes.Hidden) == (listAttributes[i] & FileAttributes.Hidden)) 
       { 
        HiddenCheck((listAttributes[i] & FileAttributes.Hidden) == FileAttributes.Hidden); 
       } 
       else 
       { 
        HiddenInvoke(CheckState.Indeterminate); 
        hiddenSet = true; 
       } 
      } 
      if (!readonlySet) 
      { 
       if ((listAttributes[i - 1] & FileAttributes.ReadOnly) == (listAttributes[i] & FileAttributes.ReadOnly)) 
       { 
        ReadOnlyCheck((listAttributes[i] & FileAttributes.ReadOnly) == FileAttributes.ReadOnly); 
       } 
       else 
       { 
        ReadOnlyInvoke(CheckState.Indeterminate); 
        readonlySet = true; 
       } 
      } 
     } 
    } 

enter image description here

+0

私は 'マルチ()'でfor'を使用することはできませんので、あなたのコードを使用しようとしませんでしたが 'それはまた'サイズ、type'が、私のようないくつかの他のものを計算しているため本当にごめんなさい申し訳ありませんが、私の質問では私のせいで言及していませんでしたが、あなたのコードは正しいと思います。 –

+0

なぜ 'for'を使うことができないのか分かりません。この 'Item item = itemCollection [i];'は 'item'を使うために使えます。 –

+0

でも可能ですが、ループは 'item.Path'から取得した他の情報があり、最初のインデックスを取得してインデックス' 1'から 'カウント-1 '。 –