2 Replies - 18615 Views - Last Post: 22 February 2011 - 03:47 AM Rate Topic: -----

#1 session123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-February 11

How to make Listview like Datagrid VBExpress 2008

Posted 21 February 2011 - 10:42 AM

I am having problem how to make a listview like a datagridview,
to be specific, how can I configure the padding of the listview items,
im using vbexpress 2008 and MS SQL 2008
here is some picture to be more specific

how can i make the padding of the items?
Attached Image
like this?
Attached Image

this is our thesis for this semester.

here is my code for simply adding items to listview from my database
        ListView1.Clear()
        ListView1.Columns.Clear()
        ListView1.Columns.Add("Student Number", 100, HorizontalAlignment.Center)
        ListView1.Columns.Add("Full Name", 150, HorizontalAlignment.Left)
        'ListView1.Columns.Add("M.I", 50, HorizontalAlignment.Left)
        'ListView1.Columns.Add("Last Name", 100, HorizontalAlignment.Left)
        ListView1.Columns.Add("Year Level", 100, HorizontalAlignment.Left)
        ListView1.Columns.Add("Section", 100, HorizontalAlignment.Left)
        'ListView1.Columns.Add("Status", 100, HorizontalAlignment.Left)
        ListView1.Columns.Add("Last Modified", 100, HorizontalAlignment.Left)
        ListView1.Columns.Add("Modified by", 100, HorizontalAlignment.Left)
        For i = 0 To myDataTable.Rows.Count - 1
            myItem = New ListViewItem
            myItem.Text = "   " + myDataTable(i).Item("stud_no").ToString
            myItem.SubItems.Add(myDataTable.Rows(i).Item("first_name").ToString + " " + myDataTable.Rows(i).Item("last_name").ToString)
            'myItem.SubItems.Add(myDataTable.Rows(i).Item("middle_name").ToString)
            'myItem.SubItems.Add(myDataTable.Rows(i).Item("last_name").ToString)
            myItem.SubItems.Add(myDataTable.Rows(i).Item("year_level").ToString)
            myItem.SubItems.Add(myDataTable.Rows(i).Item("section").ToString)
            'myItem.SubItems.Add(myDataTable.Rows(i).Item("status1").ToString)
            myItem.SubItems.Add(myDataTable.Rows(i).Item("last_modified").ToString)
            myItem.SubItems.Add(myDataTable.Rows(i).Item("modified_by").ToString)
            ListView1.Items.Add(myItem)
            status = myDataTable(i).Item("status1")
            If status = "Yes" Then
                imgindex = 1
            ElseIf status = "No" Then
                imgindex = 0
            End If
            ListView1.Items(i).ImageIndex = imgindex


            If i Mod 2 = 0 Then
                ListView1.Items(i).BackColor = Color.MistyRose
            Else
                ListView1.Items(i).BackColor = Color.White
            End If



i've been searching for an hour and it seems like every time i see a thread similar to my problem was never been provided a
correct solution.

they say that its weird that the listview in vb2008 has a no constructor of padding or i just need to upgrade my vb or my .net framework?

and also i've seen how to make it possible using WPF?

please i need help, our final defense is in this coming sunday

thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: How to make Listview like Datagrid VBExpress 2008

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1727
  • View blog
  • Posts: 5,706
  • Joined: 25-September 09

Re: How to make Listview like Datagrid VBExpress 2008

Posted 21 February 2011 - 10:53 AM

Try myItem.Text =myDataTable(i).Item("stud_no").ToString.PadLeft(20, " "c)

where 2 is the total amount of characters

For example if you used
myItem.Text = " " + myDataTable(i).Item("stud_no").ToString.PadLeft(10,"0"c)

this would pad with 0's so the number 1993857 would come out as 0001993857.
Was This Post Helpful? 0
  • +
  • -

#3 session123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-February 11

Re: How to make Listview like Datagrid VBExpress 2008

Posted 22 February 2011 - 03:47 AM

myItem.Text = " " + myDataTable(i).Item("stud_no").ToString.PadLeft(10,"0"c)


the code works!. thank you so much, i didn't know there was a constructor after the .toString

last question
is it possible to text wrap each items in the listview?

i've tried LabelWrap but it didn't work

thanks in advance
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1