DataGridView和TabControl错误? [英] DataGridView and TabControl bug?

查看:82
本文介绍了DataGridView和TabControl错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些涉及DataGridView控件和TabControls的奇怪行为。我偶然发现了一个错误,或者是否有一些我对这些控件不了解的东西?

我的应用程序使用带有五个TabPages的TabControl。每个TabPage都有自己的DataGridView,我在主窗口的FormLoad事件中绑定到DataTables。 I 在运行时设置DataGridViews的每一列的HeaderText属性,因为我事先不知道列是什么。我从我的DataTable中的DataColumn标题属性中获取标题文本。

数据绑定在所有网格上都能正常工作,其他属性也是如此,例如DataGridViewColumns的标题对齐。但HeaderText分配仅适用于第一个TabPage上的网格。只有在我第一次激活the Tab TabPage时,该分配才能在其他网格上运行。 (出于调试目的,我将HeaderText分配连接到TabPage单击事件)。

因此,只有当DataGridView位于活动TabPage上时,看起来HeaderText属性才可设置。这让我想到了这个问题:这种行为是一个错误还是设计?如何在TabPages上设置(在运行时)DataGridViews的列标题?在此先感谢。

I've come across some odd behavior involving DataGridView controls and TabControls. Have I stumbled across a bug, or is there something I don't understand about these controls?

My app uses a TabControl with five TabPages. Each TabPage has its own DataGridView, which I bind to DataTables in the main window's FormLoad event. I  set the HeaderText property of each column of the DataGridViews at run time, because I don't know in advance what the columns will be. I get the header text from the DataColumn Caption properties in my DataTable.

Data binding works fine on all grids, as do other properties, such as caption alignment for the DataGridViewColumns. But the HeaderText assignment only works for the grid on the first TabPage. The assignment works on the other grids only if I first activate theier TabPage. (For debugging purposes, I wired the HeaderText assignments to the TabPage click events).

So it looks like HeaderText property is settable only if the DataGridView is on the active TabPage. Which brings me to my question: Is this behavior a bug, or by design? How to I go about setting (at run time) the column headers of DataGridViews on TabPages? Thanks in advance.

推荐答案

这可能对你没什么帮助,但我有类似的设置,我的所有标题都按预期结束,所以仔细检查你的编码。我知道自绑定数据以来发送示例几乎是不可能的。还尝试手动将代码中的文本设置为测试,以尝试缩小问题范围。

它可能是autogeneratecolumns设置吗?检查绑定数据表的位置。你能详细说明一下你的期望和得到的东西吗?
This probably won't help you much but I have a similar setup and all my headers turn out as expected so double check your coding. I know it is nearly impossible to send an example since your binding data. Also try to manually set the text in code as a test to try to narrow the problem down.

Could it be the autogeneratecolumns setting? Check the point where you are binding the datatable too. Can you elaborate a little on what you expect and what you are getting?


这篇关于DataGridView和TabControl错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆