关于鼠标点击确定行列的问题 我用两个函数 第一个确定点击的行列 并调用 createtooltip 来显示出来 Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged Dim col As Integer Dim row As Integer col = DataGrid1.CurrentCell.ColumnNumber row = DataGrid1.CurrentCell.RowNumber Dim tooltip2 As New ToolTip(Me.components) tooltip2.AutoPopDelay = 1000 tooltip2.InitialDelay = 1000 tooltip2.ReshowDelay = 500 ' Force the ToolTip text to be displayed whether or not the form is active. tooltip2.ShowAlways = True ' Set up the ToolTip text for the Button and Checkbox. tooltip2.SetToolTip(Me.DataGrid1, "第" & row & "行 第" & col & "列") End Sub 创建tooltip 函数 Private Sub CreateMyToolTip(ByVal control As System.Windows.Forms.Control, ByVal message As String) ' Create the ToolTip and associate with the Form container. Dim toolTip1 As New ToolTip(Me.components) ' Set up the delays for the ToolTip. toolTip1.AutoPopDelay = 5000 toolTip1.InitialDelay = 10 toolTip1.ReshowDelay = 500 ' Force the ToolTip text to be displayed whether or not the form is active. toolTip1.ShowAlways = True ' Set up the ToolTip text for the Button and Checkbox. toolTip1.SetToolTip(control, message) 'toolTip1.SetToolTip(Me.DataGrid1, "数据显示窗口") End Sub
代码如下:
//手工设置datagrid列的宽度。
this.dbGrid.TableStyles["Customers"].GridColumnStyles[1].Width=800;
想要用datagrid来显示SQLserver自带的数据库northwind终customers表表中的数据,但是,在debug调试到该段代码的时候,系统报出异常“未将对象的引用设置到对象的实例”,请教这是什么原因?
这句话放到youDataGrid.DataSource=youDataSet;之后就行了。
我就是这样做的,执行顺序如下,
dbGrid.DataSource=m_DataSet.Tables["Customers"].DefaultView;
this.dbGrid.TableStyles["Customers"].GridColumnStyles[1].Width=800;
但是仍然有上面的错误,请指教!
检查一下MappingName.
TableStyles并不是我手工硬加上的,而是系统提示输入的,是不是里面的Customers表名有什么问题,或者根本就不应该填表名?如果你的可以的话,请贴出代码!谢谢!
dataAdapter.Fill(m_DataSet, "Customers");
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = "Customers"; /*?*/
......
dbGrid.TableStyles.Clear();
dbGrid.TableStyles.Add(tableStyle);
dbGrid.DataSource=m_DataSet.Tables["Customers"].DefaultView;
dbGrid.TableStyles["Customers"].GridColumnStyles[1].Width=800;也可以在属性里面设置:
MappingName = "ustomers"
第一个确定点击的行列 并调用 createtooltip 来显示出来
Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
Dim col As Integer
Dim row As Integer
col = DataGrid1.CurrentCell.ColumnNumber
row = DataGrid1.CurrentCell.RowNumber
Dim tooltip2 As New ToolTip(Me.components)
tooltip2.AutoPopDelay = 1000
tooltip2.InitialDelay = 1000
tooltip2.ReshowDelay = 500
' Force the ToolTip text to be displayed whether or not the form is active.
tooltip2.ShowAlways = True ' Set up the ToolTip text for the Button and Checkbox.
tooltip2.SetToolTip(Me.DataGrid1, "第" & row & "行 第" & col & "列")
End Sub
创建tooltip 函数
Private Sub CreateMyToolTip(ByVal control As System.Windows.Forms.Control, ByVal message As String)
' Create the ToolTip and associate with the Form container.
Dim toolTip1 As New ToolTip(Me.components)
' Set up the delays for the ToolTip.
toolTip1.AutoPopDelay = 5000
toolTip1.InitialDelay = 10
toolTip1.ReshowDelay = 500
' Force the ToolTip text to be displayed whether or not the form is active.
toolTip1.ShowAlways = True
' Set up the ToolTip text for the Button and Checkbox.
toolTip1.SetToolTip(control, message)
'toolTip1.SetToolTip(Me.DataGrid1, "数据显示窗口")
End Sub