本文介绍了在列表框中填充项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2列数字的列表框我想用零或空格填充数字,这样它们就等于3个字符,所以它们对齐。我尝试了以下代码 但我必须遗漏一些东西。


看起来像这样


4 786


123 265


34 123


128 2


我希望它看起来像这样


004 786


123 265


034 123


123 002

 Private Sub Button3_Click(sender As Object,e As EventArgs)Handles Button3.Click 


For Each c As Char in ListBox1 .Items
Dim i As String =" 1234567890"
Dim count As Integer = 0
如果i.Count = 1则
i.PadLeft(2).ToString()
ElseIf i.Count = 1则
i.PadLeft(1).ToString()
End if
Next

End Sub



解决方案


I have a list box with 2 columns of numbers I would like to pad the numbers with zeros or spaces, so that they equal 3 characters so they align. I tried the following code but I must be missing something.

Looks like this

4 786

123 265

34 123

128 2

I want it to look like this

004 786

123 265

034 123

123 002

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


        For Each c As Char In ListBox1.Items
            Dim i As String = "1234567890"
            Dim count As Integer = 0
            If i.Count = 1 Then
                i.PadLeft(2).ToString()
            ElseIf i.Count = 1 Then
                i.PadLeft(1).ToString()
            End If
        Next

    End Sub
解决方案


这篇关于在列表框中填充项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:46
查看更多