View Single Post
  #2 (permalink)  
Old January 29th, 2007, 09:20 AM
ef1196 ef1196 is offline
Authorized User
 
Join Date: Nov 2006
Location: , , USA.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

I do not think it is possible to set back colors on a listbox individually. Here is a thought on using a DataGridView to handle the task.
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        '* The DataGridView is not bound to a table, so create one column.
        Me.DataGridView1.Columns.Add("Status", "Status")
        '* Don't show the row headers or allow users to add new rows.
        '* This will make the DataGridView look similar to a listbox.
        Me.DataGridView1.RowHeadersVisible = False
        Me.DataGridView1.AllowUserToAddRows = False
        '* AutoSize the column to the size of the DataGridView.
        Me.DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        '* Create a cell and set its value and backcolor
        Dim dgvCell As New DataGridViewTextBoxCell
        dgvCell.Value = "Transaction Successfull"
        dgvCell.Style.BackColor = Color.Blue

        '* Create a new row and add to the DataGridView
        Dim dgvRow As New DataGridViewRow
        dgvRow.Cells.Add(dgvCell)
        Me.DataGridView1.Rows.Add(dgvRow)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        '* Create a cell and set its value and backcolor
        Dim dgvCell As New DataGridViewTextBoxCell
        dgvCell.Value = "Transaction Not Successfull"
        dgvCell.Style.BackColor = Color.Red

        '* Create a new row and add to the DataGridView
        Dim dgvRow As New DataGridViewRow
        dgvRow.Cells.Add(dgvCell)

        Me.DataGridView1.Rows.Add(dgvRow)

    End Sub

You could easily combine the code from button1_click and button2_click into a parameter based procedure.





Best Regards,
Earl Francis