p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Visual Basic 2005 Basics (http://p2p.wrox.com/forumdisplay.php?f=137)
-   -   How to apply text color on Listbox (http://p2p.wrox.com/showthread.php?t=53318)

h@ckerz January 29th, 2007 01:08 AM

How to apply text color on Listbox
 
Hi,
     I want to apply font color on lits box, here is the scenario..
the list box display the message if the transaction is successfull or not. if the message display successfull the color of the text is blue and if the message error or unsuccessful it colors red.. is it possible that every index in list box has assigned color? help me on this matter

................ h@ckerz ....................
If you can't join them.....HACK them
..................................................

ef1196 January 29th, 2007 09:20 AM

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

h@ckerz January 29th, 2007 08:14 PM

thanks earl.... my friend told me to use datagrid.. but i rather post this question in wrox... to have any idea from other programmer..... ineed to read more about the book... im at chapter 5 in beginning VB 2005..hehehe... i plan to convert my excel vba program to vb.net and use sql as database.... but im lack of idea from other components...

................ h@ckerz ....................
If you can't join them.....HACK them
..................................................


All times are GMT -4. The time now is 02:37 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.