Windows Develop Bookmark and Share   
 index > Windows Forms General > OwnerDrawFixed listBox problem
 

OwnerDrawFixed listBox problem

Hi,

I have a filledListBox:


private void fillmyListBox(DataTable dt)
{
this._myListBox.SelectedIndexChanged -= this._myListBox_SelectedIndexChanged;
_myListBox.DataSource = dt;
_myListBox.ValueMember = dt.Columns["ID"].ToString();
_myListBox.DisplayMember = dt.Columns["Name"].ToString();
this._myListBox.SelectedIndexChanged += this._myListBox_SelectedIndexChanged;
}



It is anOwnerDrawFixed so I add this:


void _myListBox_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
TextFormatFlags flags = TextFormatFlags.SingleLine | TextFormatFlags.Right;
if (e.Index >= 0 && e.Index < _myListBox.Items.Count)
{
Color fore = _myListBox.ForeColor;
if ((e.State & DrawItemState.Selected) != 0)
fore = SystemColors.HighlightText;

DataRowView drv = (DataRowView)this._myListBox.Items[e.Index];
TextRenderer.DrawText(e.Graphics, drv.Row.ItemArray[1].ToString(), _myListBox.Font, e.Bounds, fore, flags);
}

}

private void _myListBox_MeasureItem(object sender, MeasureItemEventArgs e)
{

ListBox theListBox = (ListBox)sender;
string itemString = (string)theListBox.Items[e.Index];

e.ItemHeight = 18;

}


And now, the problem:

Each time I want to debug one of those functions - the debuger dosen't stop runing. The list itemsis filled over and over again.

Enother problem, and I assume it accures from same reason: in run-time - if the page length is longer then the screen height - pressing on one of the items in list - causes the scroller jump tothebottom of page.

(btw, It also happenswhen pressing on text in my RichTextBox, but I'm not sure its the same problem)

I would be very happy if someone can explain me the reason for all the above.

ooorit  Tuesday, June 24, 2008 9:56 AM
Getting a breakpoint to hit over and over again in the DrawItem event is normal. When it breaks for the first time, Visual Studio comes to the foreground. When you continue running, the form comes to the foreground. Which now needs to be painted so the DrawItem event fires again. Which hits the breakpoint. Etcetera. Debugging Paint events is tricky for the same reason.

The scrollbar behavior sounds normal too. Depends how many items are in the list.
nobugz  Wednesday, June 25, 2008 3:42 AM
Getting a breakpoint to hit over and over again in the DrawItem event is normal. When it breaks for the first time, Visual Studio comes to the foreground. When you continue running, the form comes to the foreground. Which now needs to be painted so the DrawItem event fires again. Which hits the breakpoint. Etcetera. Debugging Paint events is tricky for the same reason.

The scrollbar behavior sounds normal too. Depends how many items are in the list.
nobugz  Wednesday, June 25, 2008 3:42 AM

You can use google to search for other answers

Custom Search

More Threads

• Create tree like Spy++ using Active Accessibility
• Contolling a web cam using VB.net?
• vb.NET on win98 - does it work??
• MDI child movement prevention outside parent boundaries?
• Memory Streams and SQL Server
• Drawing to a non-static panel from a static class.
• BackGroundWorker and DoWork with a Library COM invokation that halts the UI
• Enabling and Disabling DataGridView CheckBox Column
• encryption (DES)
• Using a crystal report from a dynamically loaded assembly