Automatically format listbox cells

Hey,
Anyone know a way to automatically format the cells in a listbox?
I need a way to turn the cell green or turn the font colour green or bold or something. Something to make the data stand out.
I'm reading the data in from a string array.
Rkll.

Hi Rkll,
You can use these KBs to modify the appearance of a listbox:
Change the format of the cell.
Change the font style.
Regards
JamesC
NIUK and Ireland
It only takes a second to rate an answer

Similar Messages

  • How to Format DataGridView Cells after user input, also find average of Timespans

    I'm a rather new to programming and slowly learning as best I can, and feel that I'm probably just getting hung up on some things because of my lack of overall understanding.  I've searched plenty online and these forums to figure out my issues, but
    somethings just go over my head or I can't figure out how to make it work for what I'm trying to do.
    On to what I'm trying to do.
    I'm working on building an app for scoring swim meets for our conference.  I'm using a lcal SQL DB for all of the data and have a DGV on my form.  We don't have timing systems so we take 2 times from stop watches and then need to do an average
    of the times to determine a swimmers time.  I have 3 fields for times, Time1, Time2 and AvgTime.
    What I'm needing help with is how do I allow the user to not worry about formatting the time they enter but have it automatically format what they input after they exit the cell on Time1 and Time2.  Then I need to have it figure out the average of those
    two times in AvgTime cell.  I'm able to get the averaging to work if I have the datatype set to decimal or int, but I can't get it to work if I have them set has TimeSpan.
    Below is the code I have currently.  As you can see I've got things commented out that I found online but couldn't make work.
    Thanks for taking the time to review this and help me out.
    Public Class EventScoring
    Private Sub EventScoring_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'MeetDataSet.DualLineup' table. You can move, or remove it, as needed.
    Me.DualLineupTableAdapter.Fill(Me.MeetDataSet.DualLineup)
    'TODO: This line of code loads data into the 'MeetDataSet.EventList' table. You can move, or remove it, as needed.
    Me.EventListTableAdapter.Fill(Me.MeetDataSet.EventList)
    'DualLineupDataGridView.Columns(5).DefaultCellStyle.Format = ("mm\:ss\.ff")
    MeetDataSet.DualLineup.Columns("AvgTime").Expression = "(([Time1] + [Time2]) /2)"
    End Sub
    Private Sub Sub_Btn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Sub_Btn.Click
    Try
    Me.Validate()
    Me.DualLineupBindingSource.EndEdit()
    Me.DualLineupTableAdapter.Update(Me.MeetDataSet.DualLineup)
    MsgBox("Update successful")
    Catch ex As Exception
    MsgBox("Update failed")
    End Try
    End Sub
    'Private Sub DualLineupDataGridView_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles DualLineupDataGridView.CellFormatting
    ' If ((e.ColumnIndex = 5) AndAlso (Not IsDBNull(e.Value))) Then
    ' Dim tp As TimeSpan = CType(e.Value, TimeSpan)
    ' Dim dt As DateTime = New DateTime(tp.Ticks)
    ' e.Value = dt.ToString("mm\:ss\.ff")
    ' End If
    'End Sub
    'Private Sub DualLineupDataGridView_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles DualLineupDataGridView.CurrentCellDirtyStateChanged
    ' If ((e.ColumnIndex = 5) AndAlso (Not IsDBNull(e.Value))) Then
    ' Dim tp As TimeSpan = CType(e.Value, TimeSpan)
    ' Dim dt As DateTime = New DateTime(tp.Ticks)
    ' e.Value = dt.ToString("mm\:ss\.ff")
    ' End If
    'End Sub
    End Class

    AB,
    If you're ok with your database other than working out this issue with time, you might want to give the following a try. It's pretty flexible in that you can give it a string or a decimal, and I'll explain:
    The string can be in the format of "mm:ss" (minutes and seconds) or in the format of "mm:ss:f~".
    The reason that I put the tilda there is because you're not limited on the number of decimal places - it will work out the math to figure out what you meant.
    Also though, you can give it a decimal value representing the total number of seconds. Do be sure to clearly denote that it's a decimal type (otherwise it will assume it's a double and will fail). Here's the class:
    Public Class SwimmerTime
    Private _totalSeconds As Decimal
    Public Sub New(ByVal value As Object)
    Try
    Dim tSeconds As Decimal = 0
    If TypeOf value Is String Then
    Dim s As String = CType(value, String)
    If Not s.Contains(":"c) Then
    Throw New ArgumentException("The string is malformed and cannot be used.")
    Else
    Dim elements() As String = s.Split(":"c)
    For Each element As String In elements
    If Not Integer.TryParse(element, New Integer) Then
    Throw New ArgumentException("The string is malformed and cannot be used.")
    End If
    Next
    If elements.Length = 2 Then
    tSeconds = (60 * CInt(elements(0)) + CInt(elements(1)))
    ElseIf elements.Length = 3 Then
    tSeconds = (60 * CInt(elements(0)) + CInt(elements(1)))
    Dim divideByString As String = "1"
    For Each c As Char In elements(2)
    divideByString &= "0"
    Next
    tSeconds += CDec(elements(2)) / CInt(divideByString)
    Else
    Throw New ArgumentException("The string is malformed and cannot be used.")
    End If
    End If
    ElseIf TypeOf value Is Decimal Then
    Dim d As Decimal = DirectCast(value, Decimal)
    tSeconds = d
    Else
    Throw New ArgumentException("The type was not recognizable and cannot be used.")
    End If
    If tSeconds = 0 Then
    Throw New ArgumentOutOfRangeException("Total Seconds", "Must be greater than zero.")
    Else
    _totalSeconds = tSeconds
    End If
    Catch ex As Exception
    Throw
    End Try
    End Sub
    Public Shared Function GetAverage(ByVal value1 As Object, _
    ByVal value2 As Object) As SwimmerTime
    Dim retVal As SwimmerTime = Nothing
    Try
    Dim st1 As SwimmerTime = New SwimmerTime(value1)
    Dim st2 As SwimmerTime = New SwimmerTime(value2)
    If st1 IsNot Nothing AndAlso st2 IsNot Nothing Then
    Dim tempList As New List(Of Decimal)
    With tempList
    .Add(st1.TotalSeconds)
    .Add(st2.TotalSeconds)
    End With
    Dim averageSeconds As Decimal = tempList.Average
    retVal = New SwimmerTime(averageSeconds)
    End If
    Catch ex As Exception
    Throw
    End Try
    Return retVal
    End Function
    Public ReadOnly Property FormattedString As String
    Get
    Dim ts As TimeSpan = TimeSpan.FromSeconds(_totalSeconds)
    Return String.Format("{0:00}:{1:00}:{2:000}", _
    ts.Minutes, _
    ts.Seconds, _
    ts.Milliseconds)
    End Get
    End Property
    Public ReadOnly Property TotalSeconds As Decimal
    Get
    Return _totalSeconds
    End Get
    End Property
    End Class
    I'll show how to use it by example:
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    Try
    Dim averageSwimmerTime As SwimmerTime = _
    SwimmerTime.GetAverage("02:24:05", 145.3274D)
    MessageBox.Show(String.Format("Formatted String: {0}{1}Actual Value: {2}", _
    averageSwimmerTime.FormattedString, vbCrLf, _
    averageSwimmerTime.TotalSeconds), _
    "Average Swimmer Time")
    Stop
    Catch ex As Exception
    MessageBox.Show(String.Format("An error occurred:{0}{0}{1}", _
    vbCrLf, ex.Message), "Program Error", _
    MessageBoxButtons.OK, MessageBoxIcon.Warning)
    End Try
    Stop
    End Sub
    End Class
    An advantage here is that since it returns an instance of the class, you have access to the formatted string, and the actual decimal value.
    I hope you find this helpful. :)
    Still lost in code, just at a little higher level.

  • Convert contents of a formatted excel cell to HTML format

    Hi All,
    Background: I am writing a script that uploads some test cases written in excel into Quality Center. For those who are familiar with the QC Excel Addin, this script would do a pretty similar job except for reducing
    the steps involved. I'm using Office 2007 running on Win 7 Pro.
    Need: I have a situation where the contents of a formatted excel cell need to be converted to HTML tags representing the same formattin in the excel cell. For example a cell containg the text: "Verify
    if help topics in Macro section are
    hyperlinked" should be converted to
    <html><b>Verify</b> if help topics in <u>Macro section</u> are <i>hyperlinked</i></html> 
    Question: Is there an inbuilt function in Excel/VBAn accomplish this? Or is a macro required? Any other ideas to accomplish this?
    Note: Whatever used for converting (an inbuilt function or a macro) should support new line characters and colors.
    Any help or redirection to solutions is appreciated.
    Thanks, John.
    --Thanks, John Jacob Tharakan

    Here is the function I wrote. This handles the conversion character by character.
    Function fnConvert2HTML(myCell As Range) As String
    Dim bldTagOn, itlTagOn, ulnTagOn, colTagOn As Boolean
    Dim i, chrCount As Integer
    Dim chrCol, chrLastCol, htmlTxt As String
    bldTagOn = False
    itlTagOn = False
    ulnTagOn = False
    colTagOn = False
    chrCol = "NONE"
    htmlTxt = "<html>"
    chrCount = myCell.Characters.Count
    For i = 1 To chrCount
    With myCell.Characters(i, 1)
    If (.Font.Color) Then
    chrCol = fnGetCol(.Font.Color)
    If Not colTagOn Then
    htmlTxt = htmlTxt & "<font color=#" & chrCol & ">"
    colTagOn = True
    Else
    If chrCol <> chrLastCol Then htmlTxt = htmlTxt & "</font><font color=#" & chrCol & ">"
    End If
    Else
    chrCol = "NONE"
    If colTagOn Then
    htmlTxt = htmlTxt & "</font>"
    colTagOn = False
    End If
    End If
    chrLastCol = chrCol
    If .Font.Bold = True Then
    If Not bldTagOn Then
    htmlTxt = htmlTxt & "<b>"
    bldTagOn = True
    End If
    Else
    If bldTagOn Then
    htmlTxt = htmlTxt & "</b>"
    bldTagOn = False
    End If
    End If
    If .Font.Italic = True Then
    If Not itlTagOn Then
    htmlTxt = htmlTxt & "<i>"
    itlTagOn = True
    End If
    Else
    If itlTagOn Then
    htmlTxt = htmlTxt & "</i>"
    itlTagOn = False
    End If
    End If
    If .Font.Underline > 0 Then
    If Not ulnTagOn Then
    htmlTxt = htmlTxt & "<u>"
    ulnTagOn = True
    End If
    Else
    If ulnTagOn Then
    htmlTxt = htmlTxt & "</u>"
    ulnTagOn = False
    End If
    End If
    If (Asc(.Text) = 10) Then
    htmlTxt = htmlTxt & "<br>"
    Else
    htmlTxt = htmlTxt & .Text
    End If
    End With
    Next
    If colTagOn Then
    htmlTxt = htmlTxt & "</font>"
    colTagOn = False
    End If
    If bldTagOn Then
    htmlTxt = htmlTxt & "</b>"
    bldTagOn = False
    End If
    If itlTagOn Then
    htmlTxt = htmlTxt & "</i>"
    itlTagOn = False
    End If
    If ulnTagOn Then
    htmlTxt = htmlTxt & "</u>"
    ulnTagOn = False
    End If
    htmlTxt = htmlTxt & "</html>"
    fnConvert2HTML = htmlTxt
    End Function
    Function fnGetCol(strCol As String) As String
    Dim rVal, gVal, bVal As String
    strCol = Right("000000" & Hex(strCol), 6)
    bVal = Left(strCol, 2)
    gVal = Mid(strCol, 3, 2)
    rVal = Right(strCol, 2)
    fnGetCol = rVal & gVal & bVal
    End Function
    --Thanks, John Jacob Tharakan

  • How can I create a template that does not have automatic formatting but my own?

    I have just switch to a Mac from a PC and am having a terrible time with pages.  All I want to do is create my own template that has NO AUTOMATIC FORMATTING so I can do my own.
    There is nothing in the HELP sections on how to delete the automatic formatting.  I do not want to use any of their Outline Templates just make up my own.
    I would be so so grateful if someone could help me with this.  I took a one-on-one and his idea of how to get rid of formatting in my own template DID NOT WORK!
    Thanks, Deborah

    Deborah
    Hard to see your problem, and if there is something THAT DOES NOT WORK! it would obviously be useful to know WHAT that is and WHY you believe it does not work, so we can ACTUALLY RECOMMEND A SOLUTION.
    Just select any text and change it to whatever you want using the toolbar and/or the Text inspector.
    The Outlines are just a view of your text, in a form that lets you easily organise and move it around.
    Menu > View > Show Styles Drawer
    Reveals whatever style has been applied to a heading or text and you can update or create new styles by clicking on the small triangle next to it > Redefine style from selection
    When you are finished just save it as a Template.
    Peter

  • Excel Mac £ sign keeps reverting to $ sign on saving file even when I have formatted the cells and checked the preferences

    Excel Mac - £ sign keeps reverting to $ sign on saving even though I have formatted the cells correctly to £ and in the preferences too?

    Please can you type me a response to my question. I cannot find it http://answers.microsoft.com/en-us/mac/forum/macexcel here.
    Thank you.

  • I format a cell with a double line at the bottom and it appears until I move to another cell and the formatting is lost.

    In Numbers, I format a cell with a double line at the bottom and it appears until I clik on another cell and then it disappears.

    When you describe the "double" line are you talking about something like this?
    If so this is only selecting an edge of a cell.  You still have to select:
    1) Line style using the menu to the right of the one I have circled (currently  "Thin")
    2) Line width using the menu to the right of the previous one and, finally,
    3) the line color using the menu to the right of the previous one
    Even so I have not found a way to copy cell border formatting so I ALWAYS wait until the very end to add border formatting.

  • Format a cell in Numbers

    I select some cells, choose the format but I don't see how to apply the format.  I'm obviously missing something.

    Hi Harvey,
    What format do you want?
    After selecting the cells, Format Panel > Cell > Data Format
    Please call back if this does not help.
    Regards,
    Ian.

  • How do I turn off automatic formatting of JSP pages

    Whenever I drop a component into my JSP from the component pallete JDeveloper automatically formats some "seemingly" random part of the page. This is very annoying since I spent time formatting the code the way I like it and then it's just re-written.
    I really want to turn this option off since it makes the pages almost unreadable, especially if you have a small print margin set.
    Help????

    I answered my own question. What I found happening was that every time I pasted into my JSP page the code seemed to be reformatted. What really was happening was that the indentation was being adjusted and the line formatted to fit within the specified right margin.
    If you go to Preferences|Code Editor and check off 'Adjust Indentation When Pasting' and 'Reformat Code Block When Pasting' this behavior goes away and the document stay's pretty much intact. It seems to be a good idea to increase the right margin also.
    The only formatting that occurs now is for the line you pasted and any lines below the pasted line are moved up under the pasted line.
    This change at least minimizes modifications so that if multiple developers make changes any code merges are reasonable.

  • One axis of wave chart cannot change away from automatic formatting

    Refer attached vi and picture. I can change the other two y axis to floating point, but I cannot change the "acceleration x,y,z" from automatic formating to floating point; whenever I click floating point, the highlight returns back to automatic formating.
    Now why is that, some setting wrong some where?
    Message Edited by sunflower2772 on 09-13-2009 08:00 AM
    Solved!
    Go to Solution.
    Attachments:
    Turret Motion Monitoring Software 110909b.vi ‏320 KB

    Hello Sunflower2772,
    I've opened your VI in both LabVIEW 8.6 and LabVIEW 2009, and could see the same behaviour in both versions.
    After that, I tried a few things:
    - I deleted all other scales except for the "acceleration x, y, z", but it was still the same.
    - I duplicated the "acceleration x,y,z" scale, so now there are two scales - "acceleration x,y,z" and "acceleration x,y,z 2". I shifted all but 1 of the plots to use "acceleration x,y,z 2". The result was still the same.
    It is really a strange behaviour, it looks to me like it could be a bug. Do you have the exact steps to replicate this problem?
    Anyway, I managed to get a workaround. Using one of the normal scales "Heave, roll, pitch", I duplicated that scale by right-clicking on "Heave, roll, pitch" axis, and select "Duplicate Scale". This duplicated scale can be assigned to the individual plots again, and the display format will not be "fixed" to the automatic formatting option.
    Please try it out and let me know how it goes.
    Best regards,
    Victor
    Attachments:
    Clipboard01.jpg ‏85 KB

  • Is there any way to turn off Contacts' automatical formating of phone numbers?

    Address Book's telephone fields used to be free text. You could format the phone number as desired and add comments if needed. Contacts automatically format phone number according to the ten-digit phone number (area code plus 7 digit number). If the content of a phone field does not conform to this format, the contents are all pushed together, removing any spaces that you may have entered.
    In many countries that required formating is inappropriate. Besides, it limits your freedom to add important details, like "Do not call after 7PM," etc.
    There seems no way to turn this automatical formating.

    The format for South African numbers is wrong!
    Contacts uses: +27 (xx) yyyyyyy
    Firstly the dialing code is no longer optional (for at least five years) so the brackets make no sense. Also, almost everyone uses the grouping of 3 digits then 4 digits - including official phone books.
    Its should be +27 xx yyy zzzz
    (I would also like the the auto-formatting to be optional as some other countries are crazy too).
    Is posting something here enough to get the attention of developers?

  • Format Excel cell

    Hi,
    I am writing a program that will send out an email with an excel attachment. When I open the excel file, it does show the leading zeros if the value contents only digits. For example. if the plant is '0005' the file displays just '5'. Do you know how to format the cell to text field?
    I am using FM 'SO_DOCUMENT_SEND_API1' for the email sending.
    Thanks,
    Chuong

    Hi,
    If you are using OLE automation to create the excel, you should format the cell like this:
    SET PROPERTY OF cell 'NumberFormat' = '@'.
    Regards,
    Claudiu

  • Excel 2013 VBA formatting Listbox 2 columns

    Have 2 listbox - Listbox 1 has 9 columns and is populated by Excel Worksheet Range. Listbox 1 shows formats correctly.
    User selects multiple items from Listbox1 and click a command button to inserts into Listbox2. In Listbox2 the 5th column should show data as h:mm but does not it looks like text. Also, in Listbox2 column 9 should be formatted as date mm/dd/yy and it
    is not.
    How do I write the code to format these columns?
    Code for the Command button is below:
    Private Sub CmdInsert_Click()
        Dim IndexRow As Long
        Dim IndexCol As Long
         With ListBox1
             For IndexRow = 0 To .ListCount - 1
                 If .Selected(IndexRow) Then
                     ListBox2.AddItem .List(IndexRow, 0)
                     For IndexCol = 1 To .ColumnCount - 1
                         ListBox2.List(ListBox2.ListCount - 1, IndexCol) = .List(IndexRow, IndexCol)
                         Next
                  End If
             Next
         End With
    Me.ListBox1.MultiSelect = fmMultiSelectSingle
     Me.ListBox1.ListIndex = -1
     Me.ListBox1.MultiSelect = fmMultiSelectMulti

    A listbox displays the text of the cells in its rowsource. But rowsource can only be a block of cells, so your code needs to read the text from the source cells of listbox1.
        With ListBox1
            For IndexRow = 0 To .ListCount - 1
                If .Selected(IndexRow) Then
                    ListBox2.AddItem .List(IndexRow, 0)
                    For IndexCol = 1 To .ColumnCount - 1
                        ListBox2.List(ListBox2.ListCount - 1, IndexCol) = _
                        Range(ListBox1.RowSource).Cells(IndexRow + 1, IndexCol + 1).Text
                    Next
                End If
            Next
        End With

  • Format a cell to accept text/number sequence

    I am currrently producing a spreadsheet and need to format a column to be able to automate a list of text/numbers with the number at the end being consecutive: ie-
    Pem-070412-CSP-A-001, Pem-070412-CSP-A-002 etc?
    When I have entered the first number and then drag the corner of the box down it misses out the two zeros in front of 2, 3 etc?
    I am sure that this is quite simple to achieve but for the life of me I cannot figure it out.
    Many thanks in advance.
    Derek

    The auto-increment feature isn't working well for your sequence.  Not much you can do about that so you'll have to work around it. 
    One solution:
    Put Pem-070412-CSP-A in column A
    Put 001 in column B and format the column with a special format that makes it three digits with leading zeros for unused digits (see the screenshot). Copy/drag that cell to the next row down and change that one to a 2. Select both then drag down to create your sequence of three digit numbers.
    Column C formula = A & "-" & B
    Another solution:
    Put Pem-070412-CSP-A in column A
    Put a 1 in column B of the same row and 2 in the row below. Select both and drag down to create the numerical sequence
    Column C formula =A& "-" & CHOOSE(LEN(B),"00","0","") & B
    In either case, you don't really need a column A full of "Pem-070412-CSP-A". You could just do the sequence of numbers in column A and use ="Pem-070412-CSP-" & A to create your strings.
    In either case, you could use a formula like  =B2+1 to create the sequence of numbers instead of doing it the way described above.
    If you don't want all that stuff in your table, you can copy the completed sequences from column C, paste values (not paste) them into column A, then delete columns B and C.

  • Format a cell containing a number

    How can I accomplish so that the cell shows 001 instead of 1?

    It's best to pre-format the such cells as Text. If you have just the occasional need, you can change the format to text on the fly by typing a leading single quote. '008 will show as 008 with the format changed from Automatic to Text.
    Jerry

  • How to change date format in cells?

    I have 2 cells that I cannot get the date format to appear like the other cells: I want the date to appear like this 2/19/08 and when I leave that cell it automatically turns it back to February 19, 2008. Can't seem to find any settings to get it to stay. Any suggestions?

    Selecting the cells then going to Inspector > Cell format > Date and select the one you want to use.
    You may have to set the time to None.
    Best.

Maybe you are looking for

  • How to create a report based on a DataSet programatically

    I'm working on a CR 2008 Add-in. Usage of this add-in is: Let the user choose from a list of predefined datasets, and create a totally empty report with this dataset attached to is. So the user can create a report based on this dataset. I have a data

  • How can I restore contacts from Backup Assistant

    My contact list has been corrupted. I have been using Backup Assistant for some time and want to restore my contacts from a previous backup. Verizon seems to have changed BA since the last time I used it and the only function seems to be to take my c

  • Background turns black in edit mode

    I recently coded a few templates for use in Contribute - specifically 2 different templates for 2 different designs. The HTML looks as it it needs to in the supported browsers (IE, Mozilla, Safari) and in DreamWevaer's WYSIWYG mode. It also looks fin

  • Multiple output

    After I updatet Logic 8 a few months ago, it seems I cannot use multiple outputs from battery 3. When I´m choosing Battery, I cannont choose more than 2 stereo outputs, or 4 mono. I used to be able to have 16 outputs. Seems it has something to do wit

  • JTable Data

    First...new to Java....I have a form which collects information, all address type info. There are 6 different types of addresses. There are 24 possible address fields. The address types all collect similar info...but not the same. The 24 fields is an