Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
| Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 29th, 2007, 01:08 AM
Authorized User
 
Join Date: Dec 2006
Location: Manila, , Philippines.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to h@ckerz Send a message via Yahoo to h@ckerz
Default 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
..................................................
__________________
................ h@ckerz ....................
If you can\'t join them.....HACK them
..................................................
  #2 (permalink)  
Old January 29th, 2007, 09:20 AM
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
  #3 (permalink)  
Old January 29th, 2007, 08:14 PM
Authorized User
 
Join Date: Dec 2006
Location: Manila, , Philippines.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to h@ckerz Send a message via Yahoo to h@ckerz
Default

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
..................................................


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change color of text in a listbox? ja8261 VB.NET 2002/2003 Basics 11 April 27th, 2007 10:14 AM
Need to change color of text in a text box? larry HTML Code Clinic 6 December 29th, 2006 05:14 AM
Apply Custom template & import data from text file shampabera Excel VBA 2 August 8th, 2005 07:41 AM
Need help changing color on text, please larry Javascript How-To 1 December 23rd, 2003 10:24 PM
listbox, different color for each item? MichaelTJ ADO.NET 1 November 13th, 2003 10:37 PM





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