小编Rom*_*omz的帖子

有没有在TreeView.Nodes集合中搜索TreeNode.Text字段的方法?

像这样:

TreeNode[] treeNodes = treeView.Nodes.Find(searchString, true);
Run Code Online (Sandbox Code Playgroud)

但我希望它在text现场搜索而不是name字段.

c# treeview treenode winforms

25
推荐指数
2
解决办法
4万
查看次数

TreeView搜索

此函数仅查找树视图中的第一个节点,其中包含SearchText.

private TreeNode SearchNode(string SearchText,TreeNode StartNode)
    {
        TreeNode node=null;
        while (StartNode!= null)
        {
            if (StartNode.Text.ToLower().Contains(SearchText.ToLower()))
            {
                node = StartNode; 
                break;
            };
            if (StartNode.Nodes.Count != 0) 
            {
                node=SearchNode(SearchText, StartNode.Nodes[0]);//Recursive Search
                if (node != null)
                {
                    break;
                };
            };
            StartNode = StartNode.NextNode;
        };
        return node;
    }


    private void button1_Click(object sender, EventArgs e)
    {
        string SearchText = this.textBox1.Text;
        if (SearchText == "")
        {
            return;
        };
        TreeNode SelectedNode = SearchNode(SearchText, treeView1.Nodes[0]);
        if (SelectedNode != null)
        {
            this.treeView1.SelectedNode = SelectedNode;
            this.treeView1.SelectedNode.Expand();
            this.treeView1.Select();
        }; …
Run Code Online (Sandbox Code Playgroud)

c# winforms

8
推荐指数
1
解决办法
2万
查看次数

变量未声明或从未分配警告

我有这样的代码:

这是基类:

public class BaseClass : UserControl
{
     protected ListView list;
     protected TreeView tree;

     public BaseClass()
     {
         //...
     }
     //...
}
Run Code Online (Sandbox Code Playgroud)

儿童班

public partial class MyClass : BaseClass
{
     public MyClass()
     {
         InitializeComponent();
         this.BackColor = VisualStyleInformation.TextControlBorder;
         this.Padding = new Padding(1);
     }
     //...
}

partial class MyClass
{
    //...

    private void InitializeComponent()
    {
         this.tree = new System.Windows.Forms.TreeView();
         this.list = new System.Windows.Forms.ListView();
         //...
         this.tree.Location = new System.Drawing.Point(0, 23);
         this.tree.Name = "blablabla";
    }
}
Run Code Online (Sandbox Code Playgroud)

并警告:

Warning 1 The variable 'tree' is either undeclared …
Run Code Online (Sandbox Code Playgroud)

.net c# winforms

5
推荐指数
1
解决办法
1万
查看次数

如何使用TreeViewDrawMode.OwnerDrawAll更改TreeView中所选节点的背景颜色?

我需要更改所选节点的颜色,当选择节点并具有焦点时 - 返回颜色变为绿色,选中但没有焦点 - 红色.我无法区分选定的节点与焦点在树视图和没有.位于TabPage对象中的树视图.

//...
this.myTreeView.HideSelection = false;
//...
private void myTreeView_drawNode(object sender, DrawTreeNodeEventArgs e)
{
      Color backColorSelected = System.Drawing.Color.Green;
      Color backColor = System.Drawing.Color.Red;
      // node selected and has focus
      if (((e.State & TreeNodeStates.Selected) != 0) 
      && (this.myTabControl.Focused)) // this doesn't work, node is always red
      {
          using (SolidBrush brush = new SolidBrush(backColorSelected))
          {
              e.Graphics.FillRectangle(brush, e.Bounds);
          }
      }
      // node selected but doesn't have focus
      else if ((e.State & TreeNodeStates.Selected) != 0)
      {
          using (SolidBrush brush = new SolidBrush(backColor)) …
Run Code Online (Sandbox Code Playgroud)

.net c# winforms

5
推荐指数
1
解决办法
2万
查看次数

如何拆分字符串并使用boost :: split保留分隔符?

我有一个像这样的字符串:

std::string input("I #am going to# learn how #to use #boost# library#");
Run Code Online (Sandbox Code Playgroud)

我这样做:

std::vector<std::string> splitVector;
boost::split(splitVector, input, boost::is_any_of("#"));
Run Code Online (Sandbox Code Playgroud)

得到了这个:(splitVector)

splitVector:
        "I "
        "am going to"
        " learn how " 
        "to use "
        "boos"
        " library"
        "" // **That's odd, why do I have an empty string here ?**
Run Code Online (Sandbox Code Playgroud)

但需要这样的东西:

splitVector:
    "I "
    "#am going to"
    "# learn how "
    "#to use "
    "#boost"
    "# library"
    "#"
Run Code Online (Sandbox Code Playgroud)

怎么做 ?或者也许在boost库中有另一种方法可以做到这一点?为什么我得到一个空字符串splitVector

c++ boost

4
推荐指数
1
解决办法
1717
查看次数

如何替换 TreeView 中的 TreeNode?

我是这样做的:

myTreeView.Nodes[foo] = newTreeNode.Clone(); // this doesn't work
Run Code Online (Sandbox Code Playgroud)

我想知道,如何正确地做到这一点?

编辑:我正在考虑删除旧的并插入新的树节点。

.net c# winforms

3
推荐指数
1
解决办法
1967
查看次数

如何在新过程中运行功能?

现在我处于流程的线程之一A,我需要B在当前线程中创建新流程,并在流程B函数中运行MyFunc()。我该怎么做 ?我发现了如何从当前流程创建子流程:单击。但是如何MyFunc()在这个新过程中运行?这两个进程应该异步运行,而不要像下面的示例那样互相等待:

// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
Run Code Online (Sandbox Code Playgroud)

ETA: 我在Windows上工作

c++ windows concurrency multithreading multiprocessing

3
推荐指数
1
解决办法
6917
查看次数

正则表达式翻转并合并除第一个之外的所有反斜杠

我正在尝试编写正则表达式,它将翻转和合并除第一个之外的所有反斜杠.

像这样的东西:

 C:\a\b\c\d\e         --> C:/a/b/c/d/e
 C:\a\\b\\\c\d\\\\\\e --> C:/a/b/c/d/e
 C:/a///b//c/d//////e --> C:/a/b/c/d/e
 C:\a/\/b/\c/d//\///e --> C:/a/b/c/d/e
 C:/a/b/c/d/e         --> C:/a/b/c/d/e
Run Code Online (Sandbox Code Playgroud)

\\my_share\a\b\c\d/e             --> //my_share/a/b/c/d/e
\\my_share\\\a\\\\b\c\\\//\\d\e   --> //my_share/a/b/c/d/e
\\/\my_share\\\a\\\\b\c\\\\\\d\e --> //my_share/a/b/c/d/e (if multiple '\' or\and '/' in the front - put two //)
\my_share\\\a\\\\b\c\\\\\\d\e    --> /my_share/a/b/c/d/e (if one '\' or\and '/' in the front - flip it)
my_share\\\a\\\\b\c\\\\\\d\e     --> my_share/a/b/c/d/e (if no '\' or\and '/' in the front - don't do anything)
Run Code Online (Sandbox Code Playgroud)

如何在powershell中做到这一点?$my_path -ireplace "\\", "/"

regex powershell

3
推荐指数
1
解决办法
47
查看次数

在C++中以programmaticaly方式加载资源作为字节数组

这里C#的问题相同:将资源加载为字节数组programmaticaly

所以我有一个资源(只是二进制文件 - 用户数据,并不重要).我需要一个指向表示此资源的字节数组的指针,该怎么做?资源位于vs2010的资源文件中(win32控制台项目).我想我需要使用FindResource,LoadResourceLockResourceWINAPI的功能.

c++ winapi visual-studio-2010

2
推荐指数
1
解决办法
6633
查看次数

正则表达式,用于检查字符串是否包含所有特定符号

问题是可能的字符串是:abcdefghijklmnopqrstuvwxyz(已排序)

我有另外一个字符串,可以找到像:adef

检查所有指定字符是否都在字符串中的正则表达式是什么?

测试用例:string:amnosxy find chars:osy result:true

strings:amnosxy find chars:anz result:false(z not found).

它看起来像containsAll方法

要检查的正则表达式是什么?(有可能使它在dinamically取决于查找字符串).

我不喜欢每个字符的循环解决方案,并检查IndexOf ..

c# regex string

2
推荐指数
1
解决办法
360
查看次数