简体   繁体   English

Wordwrap在VB.net中的datagridtextboxcolumn上不起作用

[英]wordwrap does not work on datagridtextboxcolumn in VB.net

I have looked at previous answers on this blog which dont seem to help me. 我看过这个博客上以前的答案,似乎对我没有帮助。

I have a datagrid and add columns that are datagridtextboxcolumn . 我有一个datagrid并添加了datagridtextboxcolumn的列。 When I click on a cell on datagrid - if the line is too big for the width of cell , it will display on the following line, but when I am not clicked on the cell, the end of the line of text will not be displayed on the next line - and is therefore not displayed. 当我在datagrid上单击一个单元格时-如果该行对于单元格的宽度而言太大,它将显示在下一行,但是当我未单击该单元格时,将不显示文本行的结尾在下一行-因此不会显示。

I derived a new class from datagridtextboxcolumn and attempted to override the paint and painttext methods and this appeared to have no effect - the text is still displayed in the column and only 1 line is displayed. 我从datagridtextboxcolumn派生了一个新类,并尝试覆盖paint和painttext方法,这似乎没有效果-文本仍显示在列中,仅显示1行。

My code is 我的代码是

Here is the derived class: - 这是派生类:-

( below I have overridden the paint and painttext class in order to see which method has some effect on the display in the datagrid - but there is no effect occuring through this process of overriding. (下面,我重写了paint和painttext类,以查看哪种方法对数据网格中的显示有一些影响-但是在此覆盖过程中没有发生任何影响。

enter code here

Imports Microsoft.VisualBasic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.Common
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Windows.Forms
Namespace DataGridRichTextBox


Public Class DataGridRichTextBoxColumn
    Inherits DataGridTextBoxColumn

    Private _source As CurrencyManager
    Private _rowNum As Integer
    Private _isEditing As Boolean



    Public Sub New()
        _source = Nothing
        _isEditing = False
    End Sub 'New



    Protected Overloads Sub PaintText(ByRef g As Graphics, ByVal bounds As System.Drawing.Rectangle, ByRef Text As String, ByVal alligntoright As Boolean)

    End Sub

    Protected Overloads Sub PaintText(ByRef g As Graphics, ByVal bounds As System.Drawing.Rectangle, ByRef Text As String, ByRef s1 As System.Drawing.Brush, ByRef s2 As System.Drawing.Brush, ByVal alligntoright As Boolean)
    End Sub

    Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal _source As CurrencyManager, ByVal num As Integer)
    End Sub

    Protected Overloads Overrides Sub SetColumnValueatrow(ByVal _source As CurrencyManager, ByVal num As Integer, ByVal obj As Object)
    End Sub

End Class 'DataGridComboBoxColumn

End Namespace 结束命名空间

'Here is where I add the derived class as an object to the datagrid : - “在这里,我将派生类作为对象添加到数据网格:-

Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Drawing




Public Class DataGridMine
    Inherits DataGrid



Public r_counter, column_num, x1 As Integer

Public x13 As Integer

#Region " Windows Form Designer generated code "


Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

 End Sub
'Form overrides dispose to clean up the component list.
 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
        If Not (components Is Nothing) Then
            components.Dispose()
        End If
    End If
    MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
Friend WithEvents SqlSelectCommand2 As New SqlCommand
Friend WithEvents DataSet51 As New tasks_trial2.DataSet5
Public WithEvents DataGridTableStyle1 As New DataGridTableStyle



Public WithEvents task_name_col, parent_col As New DataGridTextBoxColumn


Public WithEvents description_col As New DataGridRichTextBox.DataGridRichTextBoxColumn



Friend WithEvents SqlDataAdapter3 As New SqlDataAdapter

Friend WithEvents SqlDataAdapter2 As New SqlDataAdapter
Friend WithEvents SqlSelectCommand3 As New SqlCommand




   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
    CType(Priority_code_table1, System.ComponentModel.ISupportInitialize).BeginInit()



    SuspendLayout()



    Me.DataMember = "tasks"
    Me.DataSource = DataSet51
    Me.Location = New Point(8, 230)
    Me.Size = New Size(1117, 384)
    Me.TabIndex = 0


    Me.TableStyles.AddRange(New DataGridTableStyle() {DataGridTableStyle1})





    SqlDataAdapter2.SelectCommand = SqlSelectCommand2
    SqlDataAdapter2.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "tasks")})

    SqlSelectCommand2.CommandText = ""
    SqlSelectCommand2.Connection = SqlConnection10


    DataGridTableStyle1.DataGrid = Me



    DataGridTableStyle1.AllowSorting = False

    column_num = 3

    DataGridTableStyle1.HeaderForeColor = SystemColors.ControlText
    DataGridTableStyle1.MappingName = "tasks"
    DataGridTableStyle1.SelectionBackColor = Color.Aquamarine
    DataGridTableStyle1.SelectionForeColor = Color.Black
    DataGridTableStyle1.PreferredRowHeight = 10
    DataGridTableStyle1.PreferredColumnWidth = 75



    description_col.HeaderText = "Description"
    description_col.MappingName = "description"
    description_col.Width = 260

'..................... '.....................

 ' where column is description_col.


  Public Sub add_columns(ByRef dgrid1 As DataGridMine, ByVal column As Object)

        dgrid1.DataGridTableStyle1.GridColumnStyles.AddRange(New DataGridColumnStyle() {column})

    End Sub

you don't have to do all that if you use a DataGridViewTextBoxColumn 如果您使用DataGridViewTextBoxColumn,则不必执行所有操作

just have to set some option via code or properties menu 只需通过代码或属性菜单设置一些选项

go to your Columns listing and select the Column you want the text to be wrapped up and not cutt off. 请转到“列”列表,然后选择要包裹文本而不是将其截断的“列”。

go to DefaulCellStyle and set 转到DefaulCellStyle并设置

WrapMode = True

additionally you could set this on the DGV Property Menu 另外,您可以在DGV属性菜单上进行设置

AutoSizeColumnsMode to Fill

and

AutoSizeRowsMode to AllCells

that should do the Trick 这应该够了吧

this is all set in Properties Menu but you can do this in Code too so your choice 这都是在“属性”菜单中设置的,但是您也可以在“代码”中执行此操作,因此您可以选择

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM