I'm having a problem adjusting the width with listview in VB.NET where the data loaded from the database does not fit the width. Example: You have a database record that is 250 characters wide and I put the statement as follows:
If MTramo.Text = "Lobinho" Then
mlv1.Items.Clear()
Using con As MySqlConnection = GetConnection()
Try
con.Open()
Dim sql As String = ("SELECT Controle, Objetivo FROM objetivos WHERE Ramo LIKE 'Lobinho' AND Desenvolvimento = 'C-Carater' AND fase = 'a-Infância Média'")
Dim cmd As MySqlCommand = New MySqlCommand(sql, con)
Dim dr As MySqlDataReader
dr = cmd.ExecuteReader
'CONFIGURA O LISTVIEW
'=======================
'Permite o usuário rearranjar as colunas
mlv1.AllowColumnReorder = True
'Exibe as caixas de marcação
mlv1.CheckBoxes = True
'Seleciona um item e subitem quando a seleção e feita
mlv1.FullRowSelect = True
'Cria as colunas com os nomes do cabeçalho usando os nomes dos campos da tabela
With mlv1
.Columns.Add(dr.GetName(0), 80, HorizontalAlignment.Left)
.Columns.Add(dr.GetName(1), 435, HorizontalAlignment.Left)
End With
'Percorre a tabela e exibe todos os dados no listview
While dr.Read
Dim texto As String = CType(dr.Item(0), String)
Dim lv As New ListViewItem(texto, 0)
lv.SubItems.Add(New ListViewItem.ListViewSubItem(lv, CType(dr.Item(1), String)))
mlv1.Items.Add(lv)
End While
'Modo de visão
mlv1.View = View.Details
dr.Close()
I'm not able to leave the "Target" column in the required width, which would be 435. How can I do this ... if anyone can help me I'm grateful.
Follow the screen to illustrate.
=== Code in View ================
Private Sub mlv1_ItemChecked(sender As Object, e As ItemCheckedEventArgs) Handles mlv1.ItemChecked
For Each x As ListViewItem In Me.mlv1.Items
If x.Checked = True Then
If Me.mtxtOBJprg1.Text = Nothing And x.Text <> Me.mtxtOBJprg2.Text And x.Text <> Me.mtxtOBJprg3.Text Then 'verificar se TextBox1 esta vasia, se estiver add texto ...
Me.mtxtOBJprg1.Text = x.Text 'pegar o intem selecionado apenas o txt
Exit For
ElseIf Me.mtxtOBJprg2.Text = Nothing And x.Text <> Me.mtxtOBJprg1.Text And x.Text <> Me.mtxtOBJprg3.Text Then 'verificar se TextBox2 esta vasia, se estiver add texto ...
Me.mtxtOBJprg2.Text = x.Text 'pegar o intem selecionado apenas o txt
Exit For
ElseIf Me.mtxtOBJprg3.Text = Nothing And x.Text <> Me.mtxtOBJprg1.Text And x.Text <> Me.mtxtOBJprg2.Text Then 'verificar se TextBox3 esta vasia, se estiver add texto ...
Me.mtxtOBJprg3.Text = x.Text 'pegar o intem selecionado apenas o txt
Exit For
End If
Else
If x.Text = Me.mtxtOBJprg1.Text Then
Me.mtxtOBJprg1.Clear()
Exit For
ElseIf x.Text = Me.mtxtOBJprg2.Text Then
Me.mtxtOBJprg2.Clear()
Exit For
ElseIf x.Text = Me.mtxtOBJprg3.Text Then
Me.mtxtOBJprg3.Clear()
Exit For
End If
End If
Next x
End Sub