473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Focus on a custom listview

I've started writing a listview, which currently draws my list to a pane,
and onclick, works out which row you've clicked on, from the co-ordinates of
the mouse, sets the .Selected property to the index of the item in my list,
and onpaint, I draw this with a selected box over it.

It's dawned on me, that this "list", being just text written to the pane,
won't be able to recieve focus, and therefore, there's probably a better way
of doing this, where each row is a "thing", within my control... Would I be
right? And if so, can someone point me in the right direction of a
sample/doc about it? :o)

--
Daisy The Cow
Now playing: Basement Jaxx - Romeo
Nov 13 '05 #1
3 7964
You should forget the pane. Use a UserControl instead. Make a class like
this:

class MyList : UserControl {
....
}

This will have its own Control collection. So next, do this:

class MyListItem : UserControl {
....
}

This will have its own drawing code and logic. Your AddItem method will look
something like this:

class MyList : UserControl {
public void AddItem(string text) {
this.Controls.Add(new MyListItem(text));
}
}

Each of these MyListItem things will be a full control, able to receive
focus and everything. You can make them internal, so that the end user won't
be able to see them, and maybe make another class 'MyListItemPublic' that
you let the end user use to access it. Does this give you enough of a lead?

Chris

"Daisy" <da***@nospam.oops> wrote in message
news:be**********@linux01.dannytuppeny.com...
I've started writing a listview, which currently draws my list to a pane,
and onclick, works out which row you've clicked on, from the co-ordinates of the mouse, sets the .Selected property to the index of the item in my list, and onpaint, I draw this with a selected box over it.

It's dawned on me, that this "list", being just text written to the pane,
won't be able to recieve focus, and therefore, there's probably a better way of doing this, where each row is a "thing", within my control... Would I be right? And if so, can someone point me in the right direction of a
sample/doc about it? :o)

--
Daisy The Cow
Now playing: Basement Jaxx - Romeo

Nov 13 '05 #2
"Chris Capel" <ch***@nowhere.com> wrote in message
news:e7*************@TK2MSFTNGP11.phx.gbl...
You should forget the pane. Use a UserControl instead. Make a class like
this:

class MyList : UserControl {
...
}
That's what I've got, it's a class inside a control :-))

This will have its own Control collection. So next, do this:

class MyListItem : UserControl {
...
}

This will have its own drawing code and logic. Your AddItem method will look something like this:


Now that, I didn't think of. I was drawing the whole lot in my one control.

Ok, few questions :)

Firstly, wouldn't this make the tab key go through them all? This isn't how
windows works, I tab to a list, and use the cursor keys to move about...?

Secondly, I'll be "selecting" items. Since my list items are just gonne be a
row of text (I guess the onpaint method will just DrawString() for each
column at the correct ypos), should I just lash a blue box over them
OnPaint, or is there a better way (such as defining how a control with
focus, should look?)

And thirdly... Resizable columns...! Say I've got my headings (possibly
buttons, possibly just another control drawn from rectangles & 3d borders),
what's trhe best way to do this. I imagined onclick, checking the xpos to
find the end of a column heading within a few pixels, change the cursor to a
resize, and onmouseup, resize the column, however Windows does cleverer
things, such as running a line down the panel with the cursor - is there an
easy way to do that, which wouldn't involve a load of repaints?

Thanks :o)
--
Daisy The Cow
Now playing: Lene Marlin - Unforgivable Sinner
Nov 13 '05 #3
"Chris Capel" <ch***@nowhere.com> wrote in message
news:e7*************@TK2MSFTNGP11.phx.gbl...
You should forget the pane. Use a UserControl instead. Make a class like
this:

class MyList : UserControl {
...
}

This will have its own Control collection. So next, do this:

class MyListItem : UserControl {
...
}

This will have its own drawing code and logic. Your AddItem method will look something like this:

class MyList : UserControl {
public void AddItem(string text) {
this.Controls.Add(new MyListItem(text));
}
}

Each of these MyListItem things will be a full control, able to receive
focus and everything. You can make them internal, so that the end user won't be able to see them, and maybe make another class 'MyListItemPublic' that
you let the end user use to access it. Does this give you enough of a

lead?

Ok, I went ahead with your suggestion. To test the speed, vs the way I was
doing it, I set it to create 5000 items in the list. Well, that didn't work.
It took about 30 seconds to create the 5000 controls, and attach them to the
parent control. Redrawing was fine (I wrote code to Hide/Show controls,
depending on the scroll position), but there's no way I can use it as is.
It's an NNTP client I'm writing, and if someone downloads 3000 new posts, I
can't have the GUI lock up while it adds controls...

Please tell me I'm doing something wrong, because the way I did it
originally, although I was drawing my own select rectangle, and working out
what was clicked from co-ordinates, it was lightning fast to draw :-\
--
Daisy The Cow
Now playing: Aaliyah - Try Again
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rookie | last post by:
Hi, Is there any way I can keep an item in a ListView higlighted even when the ListView does not have focus. eg. If the user is modifying the row by entering values in a TextBox then the...
1
by: cider123 | last post by:
I've tried working with the SelectedIndices and Items.Selected attributes to get the problem to go away, but not having any luck. Questions I have are: 1) How do you move (using code) the...
1
by: Jeff | last post by:
I've made a custom Listview control, and i want this control to use a custom ColumnHeader control that I've created. how can i do this thanks
2
by: tmaster | last post by:
I have a form, frmMain, that contains a listview. When the user selects item(s), I do the following: Private Sub lvwToDo_ItemActivate(ByVal sender As System.Object, ByVal e As System.EventArgs)...
5
by: ToddH | last post by:
I know the following code is C#. I'm a vb programmer trying to learn a new language. I posted this in the c# group but never got a response. You guys seem to know alot about all languages and have...
2
by: Matt Michael | last post by:
Hi, I'm having a problem working with a listview in an application I'm writing. Currently, whenever the selectedindex changed event fires, it loads up a htmledit control, and other labels on the...
1
by: Tee | last post by:
Hi, In my C# application i have a treeview control and listview control, the treeview is on the left side of the from and the listview is on the right. When i click on an item in treeview i got...
7
by: =?Utf-8?B?YnJhaW5mdWVsbWVkaWE=?= | last post by:
Can anyone point me in the direction of creating a custom listview item? I guess the other question then - is this possible? I want to create a list of listview items comprised each comprised of...
0
by: =?Utf-8?B?SWdvcg==?= | last post by:
Hi everyone! I have some strange behavior of ListView control in WPF. We are developing application in C#. I created ListView with some items and set SelectedIndex to some index in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.