winform!不是要控制所有列的宽度,而是控制某一特定列的宽度!请指教!

解决方案 »

  1.   

    不好意思!问多一个问题!如何可以取到datagrid的当前被点击的行,列的值?小弟,自己想了一个办法,可以通过遍历所有的行数,判断每一行的isselected属性,可以判断是否是该行被选定,然后可以return datagrid[i,x]的值来获得相应的cell的值,但是,datagrid的总行数又该如何判断呢?请各位老大指教!
      

  2.   

    添加DataGrid中的TableStyle中的ColumnStyle,设置其Width属性
      

  3.   

    selectindex可以获得当前被点击的行
      

  4.   

    ssdjmcj8048(不爱我的我不爱) :找不到这个属性,是否你说得是在webform下的属性?我用的是winform哦!
      

  5.   

    youDataGrid.TableStyles["tablename"].GridColumnStyles[intCols].Width = Value;
      

  6.   

    sunwindone(周日华) :
    代码如下:
    //手工设置datagrid列的宽度。
    this.dbGrid.TableStyles["Customers"].GridColumnStyles[1].Width=800;
    想要用datagrid来显示SQLserver自带的数据库northwind终customers表表中的数据,但是,在debug调试到该段代码的时候,系统报出异常“未将对象的引用设置到对象的实例”,请教这是什么原因?
      

  7.   

    把this.dbGrid.TableStyles["Customers"].GridColumnStyles[1].Width=800;
    这句话放到youDataGrid.DataSource=youDataSet;之后就行了。
      

  8.   

    sunwindone(周日华) :
    我就是这样做的,执行顺序如下,
    dbGrid.DataSource=m_DataSet.Tables["Customers"].DefaultView;
    this.dbGrid.TableStyles["Customers"].GridColumnStyles[1].Width=800;
    但是仍然有上面的错误,请指教!
      

  9.   

    你的TableStyle是自己写的,还是属性里面加的,
    检查一下MappingName.
      

  10.   

    sunwindone(周日华) :
    TableStyles并不是我手工硬加上的,而是系统提示输入的,是不是里面的Customers表名有什么问题,或者根本就不应该填表名?如果你的可以的话,请贴出代码!谢谢!
      

  11.   

    这是在程序里面加的:
    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"
      

  12.   

    关于鼠标点击确定行列的问题 我用两个函数
    第一个确定点击的行列 并调用 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