|
-
Aug 12th, 2012, 01:03 PM
#1
Thread Starter
Junior Member
ListView1 partial searched text highlighted
I'm trying to do this..

I Took the a screenshot of my program and fixed it up in photoshop what i'm trying to do. See the yellow highlight and and the orange text? well i'm trying to do either one of those but i'm not sure if it's possible to do.
What i'm trying to do is when text is entered in textbox1, it will highlight or bold and color every word that has the word that is in textbox1 in listview1
Here is the code i'm trying to do this with, but it changes the whole words for color instead of just that word in textbox.
vb.net Code:
For Each sKey As ListViewItem In Me.ListView2.Items
If sKey.SubItems(0).Text.StartsWith(Me.SeedKW.Text) Then
sKey.SubItems(0).ForeColor = Color.Aqua
End If
Next
-
Aug 12th, 2012, 03:55 PM
#2
Re: ListView1 partial searched text highlighted
Moved From The CodeBank (which is for sharing code rather than posting questions )
-
Aug 12th, 2012, 04:37 PM
#3
Re: ListView1 partial searched text highlighted
It can be done but you'll have to make the listview owner draw and then do all the graphics and string drawing yourself which sounds a lot easier than it actually is on account of the metrics involved in lining up partial strings. I've done this with the simpler listbox but with only moderate success having never found a viable formula for working with changes of font.
-
Aug 12th, 2012, 06:05 PM
#4
Re: ListView1 partial searched text highlighted
Well, inspired by the question, I did some more research and I think I've cracked it. It's pumpkin time here though so you'll have to wait for an example.
-
Aug 13th, 2012, 12:12 AM
#5
Thread Starter
Junior Member
Re: ListView1 partial searched text highlighted
 Originally Posted by dunfiddlin
Well, inspired by the question, I did some more research and I think I've cracked it. It's pumpkin time here though so you'll have to wait for an example.
Well, have a happy pumpkin time (btw what does that mean? lol)
-
Aug 13th, 2012, 05:34 AM
#6
Re: ListView1 partial searched text highlighted
Hi .. i did something like this with the DGV.. check post here, you can see the result from some of the screen shots... if you want i could help you implement this into the list view (PM me)
-
Aug 13th, 2012, 08:55 AM
#7
Re: ListView1 partial searched text highlighted
 Originally Posted by Cjones636
Well, have a happy pumpkin time (btw what does that mean? lol)
Midnight! When Cinderella's carriage reverts to its original vegetable form and all good coders should be going to bed!
-
Aug 13th, 2012, 12:52 PM
#8
Thread Starter
Junior Member
Re: ListView1 partial searched text highlighted
I've been away from coding for a long time, never used listview so i can't figure out why this is so hard. It seems so simple in my head but in reality i'm beating my head up against the desk. Usually if i skip it and go do something else, then when i come back to it i kind of figure it out pretty quick.. To me this is almost like working on a car. Have you ever tried to get a nut started on a bolt that was in an awkward position, but for the life of you, you just can't get it started and when you hit your boiling point and ready to take a hammer and beat your car to death with it, you stop and go do something else then when you come back to it an an hour or 2, the nut goes right on the bolt with ease? Well to me, working on a car and coding is pretty similar is some cases.
I'm not a "master" coder by any stretch of the imagination. I Started coding in vb3 and pretty much taught myself from tutorials... Never read a book on coding or went to school for programming. I Pretty much taught myself to understand it. It's just when i start venturing outside of my knowledgeable zone, that's when it all starts looking like gibberish again.
But please no one think i'm just another code beggar, because i'm not and i do really, really try to do it on my own. I Spend plenty of days and late nights trying to do it on my own, but when i'm finally whipped and down for the 10 count i ask for help getting back up (if that made any sense to you).
I Do this as a hobby and that's it... Never sold anything i made and i always credit everyone who helped me if i share my program with the public. I'm not one of those people that takes all the credit when i had help on it.
-
Aug 13th, 2012, 02:15 PM
#9
Re: ListView1 partial searched text highlighted
Er ... right ... well.... <cough> ...
Real life being what it is I may have to give this slightly less priority than, you know, earning a living, eating and so on so I'm not setting myself any deadlines but if you want to have a try at this on your own while I dilly and dally, this is how far I got last night on the listbox project I already talked about. There are added complications with the listview but it's basically the same principle ...
vb.net Code:
Private Sub ListBox1_DrawItem(sender As System.Object, e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
' Aim: to show the last letter of a selected 3 char string in red and bold font
Dim normal As String 'the normal bit
Dim bold As String 'the bold bit
Dim NewX = e.Bounds 'the drawing rectangle
Dim f = New Font(e.Font, FontStyle.Bold)
Dim Metric As SizeF 'this determines the display size of a string
e.Graphics.PageUnit = GraphicsUnit.Pixel 'probably it is already but just to make sure
Try
If e.Index = ListBox1.SelectedIndex Then
normal = ListBox1.Items(e.Index).ToString
bold = normal.Substring(2)
normal = normal.Substring(0, 2)
Metric = e.Graphics.MeasureString(normal, e.Font, e.Bounds.Width, StringFormat.GenericTypographic) ' size the rectangle for first section
NewX.X = e.Bounds.X + Metric.Width 'move draw position to end of first section rectangle
e.Graphics.DrawString(normal, e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault)
e.Graphics.DrawString(bold, f, Brushes.Red, NewX, StringFormat.GenericDefault)
Else
e.Graphics.DrawString(ListBox1.Items(e.Index).ToString, e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault) 'everything just as it usually is
End If
Catch
End Try
End Sub
-
Aug 13th, 2012, 04:56 PM
#10
Thread Starter
Junior Member
Re: ListView1 partial searched text highlighted
 Originally Posted by dunfiddlin
Er ... right ... well.... <cough> ...
Real life being what it is I may have to give this slightly less priority than, you know, earning a living, eating and so on so I'm not setting myself any deadlines but if you want to have a try at this on your own while I dilly and dally, this is how far I got last night on the listbox project I already talked about. There are added complications with the listview but it's basically the same principle ...
vb.net Code:
Private Sub ListBox1_DrawItem(sender As System.Object, e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem ' Aim: to show the last letter of a selected 3 char string in red and bold font Dim normal As String 'the normal bit Dim bold As String 'the bold bit Dim NewX = e.Bounds 'the drawing rectangle Dim f = New Font(e.Font, FontStyle.Bold) Dim Metric As SizeF 'this determines the display size of a string e.Graphics.PageUnit = GraphicsUnit.Pixel 'probably it is already but just to make sure Try If e.Index = ListBox1.SelectedIndex Then normal = ListBox1.Items(e.Index).ToString bold = normal.Substring(2) normal = normal.Substring(0, 2) Metric = e.Graphics.MeasureString(normal, e.Font, e.Bounds.Width, StringFormat.GenericTypographic) ' size the rectangle for first section NewX.X = e.Bounds.X + Metric.Width 'move draw position to end of first section rectangle e.Graphics.DrawString(normal, e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault) e.Graphics.DrawString(bold, f, Brushes.Red, NewX, StringFormat.GenericDefault) Else e.Graphics.DrawString(ListBox1.Items(e.Index).ToString, e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault) 'everything just as it usually is End If Catch End Try End Sub
Yeah, i'll have a go at it. Well just as soon as i get done play iracing lol
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|