using System; using System.Drawing; using System.Windows.Forms; namespace QPManage.QPControls { /// <summary> /// qpDataGrid 的摘要说明。 /// </summary> public class qpDataGrid:DataGrid { private const int WM_SETCURSOR = 32; private string _strMessge="",_strMessageBoxTitle=""; int _intColumn=-1;
这个好像跟Datagrid的某一列没什么联系吧,你从数据库中查询出来的数据是什么样的顺序,绑定到DataGrid中就是什么样的。
就把AllowSorting属性设成false就可以了。
就把AllowSorting属性设成false就可以了。如果你实在要实现这样的功能,可以重写DataGrid
using System.Drawing;
using System.Windows.Forms;
namespace QPManage.QPControls
{
/// <summary>
/// qpDataGrid 的摘要说明。
/// </summary>
public class qpDataGrid:DataGrid
{
private const int WM_SETCURSOR = 32;
private string _strMessge="",_strMessageBoxTitle="";
int _intColumn=-1;
/// <summary>
/// 设置禁止排序列的属性
/// </summary>
/// <param name="intintColumn">禁止排序的列的索引</param>
/// <param name="strMessge">提示消息内容</param>
/// <param name="strMessageBoxTitle">提示消息框标题</param>
public void SetSortAttribute(int intintColumn,string strMessge,string strMessageBoxTitle)
{
_intColumn=intintColumn;
_strMessge=strMessge;
_strMessageBoxTitle=strMessageBoxTitle;
} protected override void WndProc(ref Message m)
{
if(m.Msg != WM_SETCURSOR)
base.WndProc(ref m);
else
{
// //see if you want the cursor - in col 1, rows 2, 3, 4
Point pt = this.PointToClient(Control.MousePosition);
DataGrid.HitTestInfo hti = this.HitTest(pt.X, pt.Y);
// if(hti.Column == 1 && hti.Row > 1 && hti.Row < 5)
if(hti.Type == DataGrid.HitTestType.Cell)
Cursor.Current = Cursors.Hand;
else //if not, call the baseclass
base.WndProc(ref m);
}
} protected override void OnMouseDown(MouseEventArgs e)
{
Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = this.HitTest(pt);
if(hti.Type == HitTestType.ColumnHeader && hti.Column == _intColumn)
{
MessageBox.Show(_strMessge,_strMessageBoxTitle);
return; //don't call baseclass
}
base.OnMouseDown(e);
} }
}