2014-11-30 5 views
0

나는이 블로그에서 나에게 도움이되지 않는 이전 답변을 보았습니다.wordwrap이 VB.net의 datagridtextboxcolumn에서 작동하지 않습니다.

DataGrid가 있고 datagridtextboxcolumn 인 열을 추가합니다. DataGrid에서 셀을 클릭하면 셀의 너비만큼 선이 너무 크면 다음 선에 표시되지만 셀을 클릭하지 않으면 텍스트 줄의 끝이 표시되지 않습니다. 따라서 다음 줄에 - 따라서 표시되지 않습니다.

DataGridtextboxcolumn에서 새 클래스를 파생시키고 페인트 및 painttext 메서드를 재정의하려고 시도했지만 아무 효과가없는 것으로 보입니다. 텍스트는 여전히 열에 표시되고 단 한 줄만 표시됩니다.

내 코드는 파생 클래스 여기

입니다 : -

(필자는 데이터 그리드의 표시에 약간의 영향을 어떤 방법을 참조하기 위해 페인트와 painttext 클래스를 오버라이드 (override) 한 아래 -하지만이 효과는 최우선의 과정을 통해 발생하는하지 않습니다.

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 

최종 네임 스페이스 여기

'이되어 내가 파생 클래스 A를 추가 할 경우 DataGrid를에 객체 S : - 당신은에

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 

답변

0

이 없습니다 당신이 DataGridViewTextBoxColumn에게

를 사용하는 경우 모든 것을 다만

이 정보 목록 열로 이동하여 텍스트를 싸서 오프 단편을 절단하지되어야 할 열을 선택 코드 또는 속성 메뉴를 통해 몇 가지 옵션을 설정해야합니다.

은 또한 당신이 DGV 속성 메뉴에서이 작업을 설정할 수 DefaulCellStyle로 이동

WrapMode = True 

을 설정 트릭을 할해야

AutoSizeColumnsMode to Fill 

AutoSizeRowsMode to AllCells 

이 모든 속성 메뉴에서 설정되어 있지만 너무 코드 에서이 작업을 수행 할 수 있습니다 귀하의 선택