473,385 Members | 1,553 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,385 software developers and data experts.

copying the listbox behaviour in "Add/Remove Programs"

[Problem]
I'm looking to develop a listbox with in-place editing where as each item is
selected, it grows to fit in all the text boxes. When the item is
deselected, it shrinks back to its original size. The editing bit is not a
problem, but I can't get the selected item to resize, as the listbox does
for the "Add/Remove programs".

[Approach]
The initial thought I had was to have a handler for the MeasureItem event,
then have the condition of whether the current index was selected or not,
basing the height on this.
The SelectionChange event would then call a refresh on the list box, which
in turn would cause the MeasureItem event to fire, finally leaving the
DrawItem event handler to draw the items as required.
Is this thinking logical and workable?

[code]
protected void _listBox_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
if ( e.Index < 0 )
{
selectionPanel.Hide();
return;
}

if ( (e.State & DrawItemState.Selected) ==
DrawItemState.Selected )
{
// The e.Bounds rect appears to remain unchange from the
initial
// MeasureItem event handler settings, and any changes made
// after this seems to be ignored when getting to this
method.

// put the editing panel in the selection spot
selectionPanel.Size = new Size ( e.Bounds.Width,
e.Bounds.Height );
selectionPanel.Location = new Point ( e.Bounds.Location.X+1,
e.Bounds.Location.Y+1 );
selectionPanel.BackColor = SelectedBackgroundColor;
selectionPanel.Show();

}
else
{
// draw unselected items
DrawInterfaceItem(
((InboundInterface)(_itemArray[e.Index])).name,
((InboundInterface)(_itemArray[e.Index])).type,
((InboundInterface)(_itemArray[e.Index])).messageType,
e );
}
}

private void _listBox_MeasureItem(object sender,
System.Windows.Forms.MeasureItemEventArgs e)
{
// this does indeed fire on each selection change and
// can trace the e.ItemHeight being set for selected
// items as expected.
if ( _listBox.SelectedIndex == e.Index )
{
// set the item height to that of the selection panel
e.ItemHeight = selectionPanel.Height;
}
else
{
// items not selected use a default item height
e.ItemHeight = _defaultItemHeight;
}
}

private void _listBox_SelectedIndexChanged(object sender,
System.EventArgs e)
{
// cause a redraw, and MeasureItem to fire
_listBox.Refresh();
}

Thanks for your time.
Dan.
Nov 16 '05 #1
1 2742
I managed to get this to work! Think I feel a article coming on...

It's done in short, on the following principle:
- When you reinsert an item, it fires the MeasureItem event for that item.
- You need to reinsert the newly selected index, as well as the last
selectedIndex...

Hope this helps someone else.

[code]

bool _updatingSelectedIndex = false;
bool _processingSelectionChange = false;
int _lastSelectedIndex = -1;

private void _listBox_MeasureItem(object sender,
System.Windows.Forms.MeasureItemEventArgs e)
{
if ( _updatingSelectedIndex )
{
e.ItemHeight = selectionPanel.Height;
}
else
{
e.ItemHeight = _defaultItemHeight;
}
}

private void _listBox_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if ( _listBox.Items.Count <= 0 )
{
return;
}

if ( !_processingSelectionChange )
{
_processingSelectionChange = true;

// re-evaulate the last selected item height
if ( _lastSelectedIndex >= 0 )
{
int position = _lastSelectedIndex;
Object item = _listBox.Items[position];
_listBox.Items.RemoveAt(position);
_listBox.Items.Insert(position, item);
}

_lastSelectedIndex = _listBox.SelectedIndex;

if ( !_updatingSelectedIndex && _listBox.SelectedIndex >=
)
{
_updatingSelectedIndex = true;

// re-evaulate the selected item height
int position = _listBox.SelectedIndex;
Object item = _listBox.Items[position];
_listBox.Items.RemoveAt(position);
_listBox.Items.Insert(position, item);
_listBox.SelectedIndex = position;

_updatingSelectedIndex = false;

}

_processingSelectionChange = false;

}

}

"Dan Bass" <Not Listed> wrote in message
news:OU****************@TK2MSFTNGP09.phx.gbl...
[Problem]
I'm looking to develop a listbox with in-place editing where as each item
is selected, it grows to fit in all the text boxes. When the item is
deselected, it shrinks back to its original size. The editing bit is not a
problem, but I can't get the selected item to resize, as the listbox does
for the "Add/Remove programs".

[Approach]
The initial thought I had was to have a handler for the MeasureItem event,
then have the condition of whether the current index was selected or not,
basing the height on this.
The SelectionChange event would then call a refresh on the list box, which
in turn would cause the MeasureItem event to fire, finally leaving the
DrawItem event handler to draw the items as required.
Is this thinking logical and workable?

[code]
protected void _listBox_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
if ( e.Index < 0 )
{
selectionPanel.Hide();
return;
}

if ( (e.State & DrawItemState.Selected) ==
DrawItemState.Selected )
{
// The e.Bounds rect appears to remain unchange from the
initial
// MeasureItem event handler settings, and any changes made
// after this seems to be ignored when getting to this
method.

// put the editing panel in the selection spot
selectionPanel.Size = new Size ( e.Bounds.Width,
e.Bounds.Height );
selectionPanel.Location = new Point (
e.Bounds.Location.X+1, e.Bounds.Location.Y+1 );
selectionPanel.BackColor = SelectedBackgroundColor;
selectionPanel.Show();

}
else
{
// draw unselected items
DrawInterfaceItem(
((InboundInterface)(_itemArray[e.Index])).name,
((InboundInterface)(_itemArray[e.Index])).type,
((InboundInterface)(_itemArray[e.Index])).messageType,
e );
}
}

private void _listBox_MeasureItem(object sender,
System.Windows.Forms.MeasureItemEventArgs e)
{
// this does indeed fire on each selection change and
// can trace the e.ItemHeight being set for selected
// items as expected.
if ( _listBox.SelectedIndex == e.Index )
{
// set the item height to that of the selection panel
e.ItemHeight = selectionPanel.Height;
}
else
{
// items not selected use a default item height
e.ItemHeight = _defaultItemHeight;
}
}

private void _listBox_SelectedIndexChanged(object sender,
System.EventArgs e)
{
// cause a redraw, and MeasureItem to fire
_listBox.Refresh();
}

Thanks for your time.
Dan.

Nov 16 '05 #2

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

Similar topics

0
by: Bruce | last post by:
I have three tables in SQL serve tblareas (w/autoincrement ID tblprograms (w/autoincrement ID tblphases (w/autoincrement ID I've build cascading relation from tblareas <one-many> tblprograms...
2
by: NTE | last post by:
Access 2000 and 2003. I have made a custom toolbar to allow users to filter by form, etc. The only things I want to appear on that toolbar are the 3 buttons to control filtering. At the right...
1
by: Weixiao Fan | last post by:
as we know , FONT is not availble for XHTML standard . but VS.NET 2003 add it automatically. what can I do to make all the BODY , TD , FONT and so on to body ,td ? and don`t let it add <FONT>...
4
by: eksamor | last post by:
I have a simple linked list: struct element { struct element *next; int start; }; struct list { struct element *head;
2
by: jphelan | last post by:
I was testing the install and uninstall, on my WindowsXP Pro SP2 machine, of software that I created, called, "inbusiness". Because of the following error message that I received on attempting to...
4
Cyberdyne
by: Cyberdyne | last post by:
In your All Programs Menu, some of your programs are in alphabetical order and others are not. This makes it very difficult to seek out a program that may be hidden in a maze of program folders and...
1
by: =?Utf-8?B?U3B1dG5pY2s=?= | last post by:
I am experiencing problems with add/ remove programs, It take about 3-5 minutes to build the installed programs list. I have tired cleaning out all rubbish and uninstalled unnecessary prgrams. Any...
4
by: FullBandwidth | last post by:
I have been perusing various blogs and MSDN pages discussing the use of event properties and the EventHandlerList class. I don't believe there's anything special about the EventHandlerList class in...
4
by: Sean DiZazzo | last post by:
Hi all, I'm trying to find a way to get a list of all the installed programs on a Windows box via Python. I thought of a few hacks that might partially work, and then thought about "Add/Remove...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.