Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows窗体:滚动父控件时滚动子控件_C#_.net_Datagridview_Scroll - Fatal编程技术网

C# Windows窗体:滚动父控件时滚动子控件

C# Windows窗体:滚动父控件时滚动子控件,c#,.net,datagridview,scroll,C#,.net,Datagridview,Scroll,我在.NET Windows窗体应用程序中有DataGridView控件。我还将嵌套控件放置在DataGridView的客户端区域,将DataGridView设置为嵌套控件的父控件,并设置嵌套控件的位置点。示意图: DataGridView parent = new DataGridView(); //..... Control nested = new Control(); nested.Parent = parent; nested.Location = new System.Drawin

我在.NET Windows窗体应用程序中有DataGridView控件。我还将嵌套控件放置在DataGridView的客户端区域,将DataGridView设置为嵌套控件的父控件,并设置嵌套控件的位置点。示意图:

DataGridView parent = new DataGridView(); 
//.....
Control nested = new Control();
nested.Parent = parent;
nested.Location = new System.Drawing.Point(0, 0);

但是,当我使用滚动条滚动父GridView的内容时,控件不会移动,即它不会与父GridView的内容一起滚动,而是保留在父GridView的左上角。但是,如果我希望嵌套控件始终位于GridView的第一行之后,该怎么办?是否有任何技巧可以将嵌套控件位置与GridView内容的位置同步?

这不是正确的方法。DataGridView已经可以在单元格中承载控件。这将被滚动。使用@HansPassant,我看过这篇文章,但是如何实现类似使用所描述的方法的东西呢?我试图创建并插入一个新行,其中只包含一个带有自定义控件的单元格,但DataGridView似乎不允许用户有一行(例如5个文本单元格)和下一行(一个自定义单元格)。我还需要在运行时隐藏/显示它,但仅针对选定的行。您正在设置嵌套的父级,这很好。您还需要将嵌套的
添加到要显示控件的单元格的子控件集合中。