By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,337 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,337 IT Pros & Developers. It's quick & easy.

Focus on a custom listview

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
"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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.