Mick Dugan Posted June 1, 2004 Posted June 1, 2004 I know I can format collums of data in a list box if I use a Courier font, but how do I go about it using another font? Is having several different list boxes arranged side by side the only way to do it? Regards, Mick Dugan Quote
*Experts* jfackler Posted June 1, 2004 *Experts* Posted June 1, 2004 The font shouldn't have any impact. However, keep in mind your column width is a pixel value when you set it. Also, the function of a multicolumn list box is to place items into as many columns as are needed to make vertical scrolling unnecessary. Are you trying to have multiple columns of related data? like: index1 data1 index2 data2 Check this link Quote
kejpa Posted June 1, 2004 Posted June 1, 2004 Why not use the ListView. Initially somewhat more complex and harder to learn but when you're used to it it's simply wonderful /Kejpa Quote
Mick Dugan Posted June 8, 2004 Author Posted June 8, 2004 One more question... Thanks for the responses. I was able to figure out list view with the aid of one of my reference manuals, but there's just one glitch... When I go to refresh the list view with "listView1.clear" all the formating I set up in the properties window gets erased. Is there a way to refresh the data without disturbing the columns? Or do I have to recreate it via code? Also, I'd like to be able to have the user click on the a column heading and have the order toggle from asending to decending. Any tips? Regards, Michael Dugan Quote
legendgod Posted June 8, 2004 Posted June 8, 2004 some suggestion from newbie If you want a new set of column everytime user reload the page. Use the clear function followed by the re-create column scripts. About the 2nd question do you mean sorting? How about put a button and the heading to call a function sort the column and then re-create and display? Quote http://blog.legendgod.com
*Experts* DiverDan Posted June 8, 2004 *Experts* Posted June 8, 2004 (edited) To clear a listview without disturbing the column formating use ListView1.Items.Clear() For sorting columns I use the following sub in reference to a class Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick Dim bAltSort As Boolean = False Dim MySortClass As New SortClass() Try MySortClass.column = e.Column 'Find out of we are sorting a numeric column If IsNumeric(ListView1.Items(0).SubItems(e.Column).Text.ToUpper.Trim) Then MySortClass.mNumeric = True Else : MySortClass.mNumeric = False End If 'Find out if the user is clicking on the same column. If mIntSelectedCol = e.Column Then MySortClass.AltSort = True mIntSelectedCol = -1 Else mIntSelectedCol = e.Column End If ListView1.ListViewItemSorter = MySortClass Catch 'MsgBox(Err.Description, MsgBoxStyle.Critical) End Try End Sub then the class Private mIntSelectedCol As Integer Public Class SortClass Implements IComparer Private mColumn As Integer Public mNumeric As Boolean Private m_bAltSort As Boolean Public Property column() As Integer Get Return mColumn End Get Set(ByVal Value As Integer) mColumn = Value End Set End Property Public Property Numeric() As Boolean Get Return mNumeric End Get Set(ByVal Value As Boolean) mNumeric = Value End Set End Property Public Property AltSort() As Boolean Get Return m_bAltSort End Get Set(ByVal Value As Boolean) m_bAltSort = Value End Set End Property Public Function Compare(ByVal x As Object, ByVal y As Object) _ As Integer Implements System.Collections.IComparer.Compare Dim lv1 As ListViewItem = x Dim lv2 As ListViewItem = y Try If mNumeric Then If m_bAltSort = True Then Return CLng(lv1.SubItems(mColumn).Text) + CDbl(lv2.SubItems(mColumn).Text) Else Return CDbl(lv2.SubItems(mColumn).Text) - CDbl(lv1.SubItems(mColumn).Text) End If Else If m_bAltSort = True Then Return String.Compare(lv2.SubItems(mColumn).Text, lv1.SubItems(mColumn).Text) Else Return String.Compare(lv1.SubItems(mColumn).Text, lv2.SubItems(mColumn).Text) End If End If Catch End Try End Function End Class Edited June 8, 2004 by DiverDan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
kejpa Posted June 8, 2004 Posted June 8, 2004 Hey DiverDan, does this really, really work?!?!? If mNumeric Then If m_bAltSort = True Then Return CLng(lv1.SubItems(mColumn).Text) + CDbl(lv2.SubItems(mColumn).Text) Else Return CDbl(lv2.SubItems(mColumn).Text) - CDbl(lv1.SubItems(mColumn).Text) End If Firstly, You're not comparing, you're adding/subtracting according to my universe. Secondly, If m_bAltSirt=true you're adding a Long with a double I'd have it this way If mNumeric Then If m_bAltSort = True Then Return CDbl(lv1.SubItems(mColumn).Text) > CDbl(lv2.SubItems(mColumn).Text) Else Return CDbl(lv2.SubItems(mColumn).Text) > CDbl(lv1.SubItems(mColumn).Text) End If [/codE] Another thing that might screw up is if you have text and numeric values in the same column, and the first is numeric. Then you will try to sort the listview as if the whole column was numeric and that won't work. Isn't it better to mark the column as numeric when you fill it? IMHO Kejpa Quote
*Experts* DiverDan Posted June 8, 2004 *Experts* Posted June 8, 2004 You know, I haven't really taken to time to look at the code closely BUT.... Yes, It Really, Really Works....very well also. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
kejpa Posted June 8, 2004 Posted June 8, 2004 Sorry if I offended you. I was just surprised over the matters I pointed out. I will use (the modified) code and I'm thankful for what you've done. /Kejpa Quote
*Experts* Nerseus Posted June 8, 2004 *Experts* Posted June 8, 2004 (I hate open questions): If you really wanted to use a Listbox with "tabs", you'd have to use the Win API SendMessage. Something like this in C#: public class Form1 : Form { // Declare the DLL function at the top of a class [DllImport("user32", EntryPoint="SendMessage")] private static extern int SendMessageTabStops(int handle, int msg, int tabCount, int[] tabStops); private const int LB_SETTABSTOPS = 0x192; private void SetTabStops() { listBox1.Items.Add("dan\tbob\tMe"); listBox1.Items.Add("bob\tbob\tHim"); listBox1.Items.Add("hagatha\tbob\tHer"); int[] tabStops = new int[] {0, 50, 100}; SendMessageTabStops(listBox1.Handle.ToInt32(), LB_SETTABSTOPS, tabStops.Length, tabStops); } } -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.