int _UnSortColumn = -1; /// <summary> /// 不允许排序的列号 /// </summary> public int UnSortColumn { get { return _UnSortColumn; } set { _UnSortColumn = value; } } protected override void OnMouseDown(MouseEventArgs e) { HitTestInfo info = this.HitTest(e.X,e.Y); if(info.Column == this.UnSortColumn && info.Type == HitTestType.ColumnHeader) { return; } base.OnMouseDown (e); }
1.可以不用DataTable或DataSet绑定DataGrid,而用DataView绑定DataGrid,DataView有Sort 属性,用它排序。 2. 5.58 How can I put up a confirmation question when the user tries to delete a row in the datagrid by clicking on the row header and pressing the Delete key? http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q889q
根据 CMIC(大象) 提供链接转载 1.How do I prevent sorting a single column in my DataGrid? You can do this by deriving the DataGrid and overriding OnMouseDowm. In your override, do a HitText and if the hit is on a column header that you do not want to sort, do not call the baseclass. Here is a code that sorts all columns except the second column
2.How can I put up a confirmation question when the user tries to delete a row in the datagrid by clicking on the row header and pressing the Delete key? You can handle this by subclassing your grid and overriding either PreProcessMessage or ProcessDialogKey. The code below assumes your datasource is a dataview. If it is not, you could just remove that check
[C#]
public override bool PreProcessMessage( ref Message msg )
/// <summary>
/// 不允许排序的列号
/// </summary>
public int UnSortColumn
{
get
{
return _UnSortColumn;
}
set
{
_UnSortColumn = value;
}
} protected override void OnMouseDown(MouseEventArgs e)
{
HitTestInfo info = this.HitTest(e.X,e.Y);
if(info.Column == this.UnSortColumn && info.Type == HitTestType.ColumnHeader)
{
return;
}
base.OnMouseDown (e);
}
属性,用它排序。
2.
5.58 How can I put up a confirmation question when the user tries to delete a row in the datagrid by clicking on the row header and pressing the Delete key?
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q889q
1.How do I prevent sorting a single column in my DataGrid? You can do this by deriving the DataGrid and overriding OnMouseDowm. In your override, do a HitText and if the hit is on a column header that you do not want to sort, do not call the baseclass. Here is a code that sorts all columns except the second column
[C#]
//derived class
public class MyDataGrid : DataGrid
{
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 == 1)
{
//don't sort col 1
return; //don't call baseclass
}
base.OnMouseDown(e);
}
}
2.How can I put up a confirmation question when the user tries to delete a row in the datagrid by clicking on the row header and pressing the Delete key? You can handle this by subclassing your grid and overriding either PreProcessMessage or ProcessDialogKey. The code below assumes your datasource is a dataview. If it is not, you could just remove that check
[C#]
public override bool PreProcessMessage( ref Message msg )
{
Keys keyCode = (Keys)(int)msg.WParam & Keys.KeyCode;
if(msg.Msg == WM_KEYDOWN
&& keyCode == Keys.Delete
&& ((DataView) this.DataSource).AllowDelete)
{
if(MessageBox.Show("Delete this row?", "", MessageBoxButtons.YesNo) == DialogResult.No)
return true;
}
return base.PreProcessMessage(ref msg);
}
2.网页可以打开你在试试。