Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.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# 将自定义HScroll绑定到DataGridView 我在将Hscroll绑定到datagridview时遇到问题。我需要一个比默认DGV更大的烤盘。所以我需要绑定自定义滚动到dgv或增加默认滚动的高度。我正在使用WinForms。_C#_Winforms_Datagridview_Horizontal Scrolling - Fatal编程技术网

C# 将自定义HScroll绑定到DataGridView 我在将Hscroll绑定到datagridview时遇到问题。我需要一个比默认DGV更大的烤盘。所以我需要绑定自定义滚动到dgv或增加默认滚动的高度。我正在使用WinForms。

C# 将自定义HScroll绑定到DataGridView 我在将Hscroll绑定到datagridview时遇到问题。我需要一个比默认DGV更大的烤盘。所以我需要绑定自定义滚动到dgv或增加默认滚动的高度。我正在使用WinForms。,c#,winforms,datagridview,horizontal-scrolling,C#,Winforms,Datagridview,Horizontal Scrolling,我尝试了以下代码,但它不符合我的需要,滚动在我的dgv中间停止,操纵值对它没有任何影响 private void dataGridView1_Scroll(object sender, ScrollEventArgs e) { int totalwidth = dataGridView1.RowHeadersWidth; for (int i = 0; i < dataGridView1.Columns.Count; i++) { totalwid

我尝试了以下代码,但它不符合我的需要,滚动在我的dgv中间停止,操纵值对它没有任何影响

private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
{
    int totalwidth = dataGridView1.RowHeadersWidth;

    for (int i = 0; i < dataGridView1.Columns.Count; i++)
    {
        totalwidth += dataGridView1.Columns[i].Width  ;
    }

    hScrollBar1.LargeChange = dataGridView1.Width;
    hScrollBar1.SmallChange = dataGridView1.Columns[gsKodTowaruDataGridViewTextBoxColumn.Index].Width;

    if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
    {
        hScrollBar1.Value = e.NewValue;          
    }
}

private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)           
{
    dataGridView1.HorizontalScrollingOffset = e.NewValue;
}
private void dataGridView1\u滚动(对象发送方,ScrollEventArgs e)
{
int totalwidth=dataGridView1.RowHeadersWidth;
对于(int i=0;i

谢谢您的回答。

您必须绑定这些值才能对更改做出反应,对吗? 您正在使用maxWidth值,但未使用它


此外,您应该对DataGridView上的Resize事件做出反应,以确保HScroll值发生更改。

如何设置最大值?也许
totalwidth
?是的,它不适合这样工作。你说的a)“不合适”和b)是什么意思。如果没有正确设置最大值,滚动条显然无法工作。您还需要在添加列或调整列大小时对其进行调整。显示代码!a) -不会一直移动,移动到大约“默认”滚动条长度的50%。--hScrollBar1.最大值=总宽度;hScrollBar1.LargeChange=dataGridView1.Width+50;hScrollBar1.SmallChange=dataGridView1.Columns[gskodtowarDataGridViewTextBoxColumn.Index]。宽度;在for循环之后,现在看起来是这样的^^一个简单的解决方案是与dgv的hscrollbar同步:
hScrollBar1.max=totalwidth;HScrollBar vBar=dataGridView1.Controls.OfType().First();hScrollBar1.LargeChange=vBar!=无效的vBar.LargeChange:总宽度/4我的坏,我无意中删除了hScrollbar1。最大值=总宽度。但它不是这样工作的。嗯,它工作,但最大似乎是在DGV中部的某处。