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

intercepting datagrid column header click? Bug?

P: n/a
My Windows datagrid has two columns: one with the data that the user will
see (col_X) and the other one (a hidden one: col_sort) that'll be used to
sort data. When a user clicks on col_X's column header, I'm intercepting the
header click and "telling" it to sort the dataview using col_sort. But for
some reason, the "return" is not being executed. When I press the mouse key,
it'll sort correctly (by col_sort), but as soon as I release the button,
it'll sort by col_x. This is my code:

private void dataGrid_browse_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
DataGrid.HitTestInfo hitTest;
if (e.Button == MouseButtons.Left)
hitTest = dataGrid_browse.HitTest(e.X, e.Y);
if (hitTest.Type == DataGrid.HitTestType.ColumnHeader)
DataView dtView = (DataView)dataGrid_browse.DataSource;
if (hitTest.Column == 4) //column 4 is col_X
dtView.Sort = "col_sort ASC";
return; //without messageBox or breakpoint , this
instruction is ignored

If I put a breakpoint or put a Messagebox inside the "if (hitTest.Column ==
4)" (I force the program to pause), it'll work. But if it does it
continuously, it'll sort by col_sort and then sort by col_x. The "return" is

Any help is appreciated.

Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.