zoukankan      html  css  js  c++  java
  • 重绘datagrid,包括强迫显示某行

    #Region "用来对DataGrid的显示样式进行重绘"
        Private Sub FormatGridWithTableStyles()
            Dim ts As New DataGridTableStyle    '就是它决定了datagrid是什么样的

            Dim aColumnTextColumn As DataGridTextBoxColumn '要重写的东东

            ts.MappingName = datagridTable.TableName

            Dim numCols As Integer

            numCols = datagridTable.Columns.Count

            Dim i As Integer = 0

            Do While (i < numCols) '重绘所有的列

                aColumnTextColumn = New DataGridTextBoxColumn

                '夺过对textbox内落下光标的控制权

                AddHandler aColumnTextColumn.TextBox.Enter, New EventHandler(AddressOf TextBoxEnterHandler)

                '要更改列头名,请改下句的HeaderText值

                aColumnTextColumn.HeaderText = datagridTable.Columns(i).ColumnName

                '更改列的实际内容
                aColumnTextColumn.MappingName = datagridTable.Columns(i).ColumnName

                '自动改变行宽不对
                aColumnTextColumn.TextBox.AutoSize = True
                'MsgBox(aColumnTextColumn.HeaderText.ToString)
                'Debug.Write(aColumnTextColumn.TextBox.Width & "aa")

                '自动改变行宽不对
                aColumnTextColumn.TextBox.AutoSize = True

                ts.PreferredColumnWidth = aColumnTextColumn.TextBox.Width()

                ts.GridColumnStyles.Add(aColumnTextColumn)  '增加一种自定义的column风格


                i = (i + 1)

            Loop

            DataGrid1.TableStyles.Clear()

            DataGrid1.TableStyles.Add(ts) '增加一种自定义的表风格

        End Sub
    #End Region

    #Region "当点击时强迫datagrid选中某行,而不是某行某列"
        Private Sub TextBoxEnterHandler(ByVal sender As Object, ByVal e As System.EventArgs)

            Dim inner As Control = sender

            inner.Visible = False

            DataGrid1.Select(DataGrid1.CurrentRowIndex)

        End Sub
    #End Region

  • 相关阅读:
    网页弹窗代码大全收集整理
    再来二十一段救命的PHP代码
    PHP文件包含漏洞原理分析和利用方法
    Apache重写规则的常见应用及实例说明
    PHPCMS 整站代码分析讲解(一)
    网络登录过程
    lamp安装的所有注意事项
    使用lockbits方法处理图像 from http://blog.sina.com.cn/s/blog_4e3e2ce4010009on.html
    CImage类 from http://www.cnblogs.com/afarmer/archive/2012/03/31/2427273.html
    VC/MFC怎样将位图CBitmap对象保存成为bmp格式文件? from http://coding1688.iteye.com/blog/1547035
  • 原文地址:https://www.cnblogs.com/zyizyizyi/p/2497868.html
Copyright © 2011-2022 走看看