本文整理汇总了C#中System.Windows.Forms.DataGridViewSortCompareEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# DataGridViewSortCompareEventArgs类的具体用法?C# DataGridViewSortCompareEventArgs怎么用?C# DataGridViewSortCompareEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataGridViewSortCompareEventArgs类属于System.Windows.Forms命名空间,在下文中一共展示了DataGridViewSortCompareEventArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EquipmentView_SortCompare
private void EquipmentView_SortCompare( object sender, DataGridViewSortCompareEventArgs e ) {
if ( e.Column.Index == EquipmentView_Name.Index ) {
int id1 = (int)EquipmentView[EquipmentView_ID.Index, e.RowIndex1].Value;
int id2 = (int)EquipmentView[EquipmentView_ID.Index, e.RowIndex2].Value;
e.SortResult =
KCDatabase.Instance.MasterEquipments[id1].CategoryType -
KCDatabase.Instance.MasterEquipments[id2].CategoryType;
if ( e.SortResult == 0 ) {
e.SortResult = id1 - id2;
}
} else {
e.SortResult = ( (IComparable)e.CellValue1 ).CompareTo( e.CellValue2 );
}
if ( e.SortResult == 0 ) {
e.SortResult = ( EquipmentView.Rows[e.RowIndex1].Tag as int? ?? 0 ) - ( EquipmentView.Rows[e.RowIndex2].Tag as int? ?? 0 );
}
e.Handled = true;
}
示例2: DataGridView_SortCompare
void DataGridView_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
//verifica se é a mesma coluna, se não for... ignora
if(e.Column.Index == this.Index)
{
double cellValue1 = Double.Parse(Unimake.Utilities.OnlyNumbers(e.CellValue1).ToString());
double cellValue2 = Double.Parse(Unimake.Utilities.OnlyNumbers(e.CellValue2).ToString());
e.SortResult = cellValue1.CompareTo(cellValue2);
e.Handled = true;
}
}
示例3: dgvWirelessNetworks_SortCompare
private void dgvWirelessNetworks_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
if (e.Column.Index == 4)
{
int a = int.Parse(e.CellValue1.ToString());
int b = int.Parse(e.CellValue2.ToString());
// If the cell value is already an integer, just cast it instead of parsing
e.SortResult = a.CompareTo(b);
e.Handled = true;
}
}
示例4: dataGridSymbols_SortCompare
private void dataGridSymbols_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
if (e.Column.Index > 0)
{
e.Handled = true;
int val1;
int val2;
Int32.TryParse(e.CellValue1.ToString(), out val1);
Int32.TryParse(e.CellValue2.ToString(), out val2);
e.SortResult = val1 - val2;
}
}
示例5: dataGridViewStorage_SortCompare
void dataGridViewStorage_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
if (e.Column == ColumnDevicePosition)
{
e.SortResult = StringUtility.NaturalCompare(e.CellValue1.ToString(), e.CellValue2.ToString());
e.Handled = true;
}
else
{
e.Handled = false;
}
}
示例6: dgrid_SortCompare
/// <summary>
/// manejador del evento SortCompare de la grilla
/// </summary>
/// <param name="sender">Objeto donde se generó el evento --> la grilla</param>
/// <param name="e">Argumento del evento que contiene información sobre las filas y columnas que se comparan</param>
private void dgrid_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
// si la columna es de tipo int, entonces realiza el ordenamiento de números enteros
if (e.Column.ValueType == typeof(int))
{
// obtiene el valor entero de cada celda
int value1 = int.Parse(e.CellValue1.ToString());
int value2 = int.Parse(e.CellValue2.ToString());
// compara dichos valores usando el método CompareTo de la clase int. La clase int implemente IComparable<int>
e.SortResult = value1.CompareTo(value2);
// indica que se realizó el manejo del evento
e.Handled = true;
}
// si la columna es de tipo decimal, entonces realiza el ordenamiento de números decimales
else if (e.Column.ValueType == typeof(decimal))
{
// obtiene el valor decimal de cada celda
decimal value1 = decimal.Parse(e.CellValue1.ToString());
decimal value2 = decimal.Parse(e.CellValue2.ToString());
// compara dichos valores usando el método CompareTo de la clase decimal. La clase decimal implemente IComparable<decimal>
e.SortResult = value1.CompareTo(value2);
// indica que se realizó el manejo del evento
e.Handled = true;
}
// si la columna es de tipo DateTime, entonces realiza el ordenamiento de fechas
else if (e.Column.ValueType == typeof(DateTime))
{
// obtiene el valor fecha de cada celda
DateTime value1 = DateTime.Parse(e.CellValue1.ToString());
DateTime value2 = DateTime.Parse(e.CellValue2.ToString());
// compara dichos valores usando el método CompareTo de la clase DateTime. La clase DateTime implemente IComparable<DateTime>
e.SortResult = value1.CompareTo(value2);
// indica que se realizó el manejo del evento
e.Handled = true;
}
}
示例7: dgvLeases_SortCompare
private void dgvLeases_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
string val1 = e.CellValue1?.ToString() ?? "";
string val2 = e.CellValue2?.ToString() ?? "";
//TODO: This is inefficient, requires potentially processing the same IPAddress or Date values over and over again
// It doesn't seem to cause noticable delays, so low priority, but I'd still like to refactor
// this to re-use parsed values.
int result = 0;
if (val1 == "" && val2 != "")
{
result = -1;
}
else if (val1 != "" && val2 == "")
{
result = 1;
}
else if (val1 == "" && val2 == "")
{
result = 0;
}
//neither value is empty. Now we can process special columns
else if (e.Column.HeaderText == "IP Address")
{
uint v1 = (uint)System.Net.IPAddress.NetworkToHostOrder((int)System.Net.IPAddress.Parse(val1).Address);
uint v2 = (uint)System.Net.IPAddress.NetworkToHostOrder((int)System.Net.IPAddress.Parse(val2).Address);
result = v1.CompareTo(v2);
}
else if (e.Column.HeaderText == "Expires")
{
DateTime v1 = DateTime.Parse(val1);
DateTime v2 = DateTime.Parse(val2);
result = v1.CompareTo(v2);
}
//default
else
{
result = val1.CompareTo(val2);
}
e.SortResult = result;
e.Handled = true;
}
示例8: ShipView_SortCompare
private void ShipView_SortCompare( object sender, DataGridViewSortCompareEventArgs e )
{
if ( e.Column.Index == ShipView_Name.Index ) {
e.SortResult =
KCDatabase.Instance.MasterShips[(int)ShipView.Rows[e.RowIndex1].Cells[e.Column.Index].Tag].AlbumNo -
KCDatabase.Instance.MasterShips[(int)ShipView.Rows[e.RowIndex2].Cells[e.Column.Index].Tag].AlbumNo;
} else if ( e.Column.Index == ShipView_Exp.Index ) {
e.SortResult = (int)e.CellValue1 - (int)e.CellValue2;
if ( e.SortResult == 0 ) //for Lv.99-100
e.SortResult = (int)ShipView[ShipView_Level.Index, e.RowIndex1].Value - (int)ShipView[ShipView_Level.Index, e.RowIndex2].Value;
} else if (
e.Column.Index == ShipView_HP.Index ||
e.Column.Index == ShipView_Fuel.Index ||
e.Column.Index == ShipView_Ammo.Index ||
e.Column.Index == ShipView_Aircraft1.Index ||
e.Column.Index == ShipView_Aircraft2.Index ||
e.Column.Index == ShipView_Aircraft3.Index ||
e.Column.Index == ShipView_Aircraft4.Index ||
e.Column.Index == ShipView_Aircraft5.Index ||
e.Column.Index == ShipView_AircraftTotal.Index
) {
Fraction frac1 = (Fraction)e.CellValue1, frac2 = (Fraction)e.CellValue2;
double rate = frac1.Rate - frac2.Rate;
if ( rate > 0.0 )
e.SortResult = 1;
else if ( rate < 0.0 )
e.SortResult = -1;
else
e.SortResult = frac1.Current - frac2.Current;
} else if ( e.Column.Index == ShipView_Fleet.Index ) {
if ( (string)e.CellValue1 == "" ) {
if ( (string)e.CellValue2 == "" )
e.SortResult = 0;
else
e.SortResult = 1;
} else {
if ( (string)e.CellValue2 == "" )
e.SortResult = -1;
else
e.SortResult = ( (string)e.CellValue1 ).CompareTo( e.CellValue2 );
}
} else {
e.SortResult = (int)e.CellValue1 - (int)e.CellValue2;
}
if ( e.SortResult == 0 ) {
e.SortResult = (int)ShipView.Rows[e.RowIndex1].Tag - (int)ShipView.Rows[e.RowIndex2].Tag;
if ( ShipView.SortOrder == SortOrder.Descending )
e.SortResult = -e.SortResult;
}
e.Handled = true;
}
示例9: DataGridViewObject_SortCompare
void DataGridViewObject_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
if (e.Column.Index == sizeColumn.Index)
{
VDI vdi1 = ((VDIRow)dataGridViewVDIs.Rows[e.RowIndex1]).VDI;
VDI vdi2 = ((VDIRow)dataGridViewVDIs.Rows[e.RowIndex2]).VDI;
long diff = vdi1.virtual_size - vdi2.virtual_size;
e.SortResult =
diff > 0 ? 1 :
diff < 0 ? -1 :
0;
e.Handled = true;
}
}
示例10: OnSortCompare
protected virtual void OnSortCompare (DataGridViewSortCompareEventArgs e) {
DataGridViewSortCompareEventHandler eh = (DataGridViewSortCompareEventHandler)(Events [SortCompareEvent]);
if (eh != null) eh (this, e);
}
示例11: sharedFilesDataGridView_SortCompare
private void sharedFilesDataGridView_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
switch (e.Column.Name)
{
case "RatingIcon":
e.SortResult = ((byte)sharedFilesDataGridView.Rows[e.RowIndex1].Cells[e.Column.Name].Tag + ((RandomTag<string>)sharedFilesDataGridView.Rows[e.RowIndex1].Tag).SortTag).CompareTo((byte)sharedFilesDataGridView.Rows[e.RowIndex2].Cells[e.Column.Name].Tag + ((RandomTag<string>)sharedFilesDataGridView.Rows[e.RowIndex2].Tag).SortTag);
e.Handled = true;
break;
case "FileSize":
// 2007-05-17 T.Norad: fix for big files
e.SortResult = ((long)sharedFilesDataGridView.Rows[e.RowIndex1].Cells[e.Column.Name].Tag + ((RandomTag<string>)sharedFilesDataGridView.Rows[e.RowIndex1].Tag).SortTag).CompareTo((long)sharedFilesDataGridView.Rows[e.RowIndex2].Cells[e.Column.Name].Tag + ((RandomTag<string>)sharedFilesDataGridView.Rows[e.RowIndex2].Tag).SortTag);
e.Handled = true;
break;
case "lastRequest":
// get the first value to compare from grid
object date1 = sharedFilesDataGridView.Rows[e.RowIndex1].Cells[e.Column.Name].Tag;
// second value from grid
object date2 = sharedFilesDataGridView.Rows[e.RowIndex2].Cells[e.Column.Name].Tag;
e.SortResult = SortHelper.compareDates(date1, date2);
// if the datetime equal we use the sort tag to prevent flickering sort results
if (e.SortResult == 0)
{
e.SortResult = ((RandomTag<string>)sharedFilesDataGridView.Rows[e.RowIndex1].Tag).SortTag.CompareTo(((RandomTag<string>)sharedFilesDataGridView.Rows[e.RowIndex2].Tag).SortTag);
}
e.Handled = true;
break;
}
}
示例12: dataGridView1_SortCompare
private void dataGridView1_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
try {
if (e.Column.Name.Equals("CSize")) {
//if (e.CellValue1.Equals(e.CellValue2)) {
// e.SortResult = -1;
// e.Handled = true;
//}
String[] data1 = MyReg.Reg_GetFirstMutiString(e.CellValue1.ToString(), "(\\d+\\.?\\d*)+\\s*(GB|MB)");
String[] data2 = MyReg.Reg_GetFirstMutiString(e.CellValue2.ToString(), "(\\d+\\.?\\d*)+\\s*(GB|MB)");
double ddata1 = double.Parse(data1[0]); int flag1 = data1[1].Equals("MB") ? 0 : 1;
double ddata2 = double.Parse(data2[0]); int flag2 = data2[1].Equals("MB") ? 0 : 1;
int flag = flag1 - flag2;
if (flag == 0) { //单位相同比大小
flag = (ddata1 - ddata2) >= 0 ? 1 : -1;
}
e.SortResult = flag;
e.Handled = true;
} else if (e.Column.Name.Equals("CHot") || e.Column.Name.Equals("CNum")) {//热度排序和index排序
int data1 = MyReg.Reg_GetFirstNum(e.CellValue1.ToString(), "(\\d+)");
int data2 = MyReg.Reg_GetFirstNum(e.CellValue2.ToString(), "(\\d+)");
e.SortResult = data1 - data2;
e.Handled = true; //不要会炸
}
}
catch (Exception ee) {
Console.WriteLine("我日了狗"+ee.Message);
}
// 如果是学号或成绩列,则按浮点数处理
//if (e.Column.Name == "大小")
//{
// if(data1.)
// e.SortResult = (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) > 0) ? 1 : (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) < 0) ? -1 : 0;
// e.Handled = true;
//}
////否则,按字符串比较
//else
//{
// return;
//}
}
示例13: connectionsDataGridView_SortCompare
private void connectionsDataGridView_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
switch (e.Column.Name)
{
case "IPAddress":
e.SortResult = ((uint)connectionsDataGridView.Rows[e.RowIndex1].Cells[e.Column.Name].Tag + ((RandomTag<IPAddress>)connectionsDataGridView.Rows[e.RowIndex1].Tag).SortTag).CompareTo((uint)connectionsDataGridView.Rows[e.RowIndex2].Cells[e.Column.Name].Tag + ((RandomTag<IPAddress>)connectionsDataGridView.Rows[e.RowIndex2].Tag).SortTag);
e.Handled = true;
break;
case "EnqueuedCommands":
e.SortResult = ((int)connectionsDataGridView.Rows[e.RowIndex1].Cells[e.Column.Name].Tag + ((RandomTag<IPAddress>)connectionsDataGridView.Rows[e.RowIndex1].Tag).SortTag).CompareTo((int)connectionsDataGridView.Rows[e.RowIndex2].Cells[e.Column.Name].Tag + ((RandomTag<IPAddress>)connectionsDataGridView.Rows[e.RowIndex2].Tag).SortTag);
e.Handled = true;
break;
case "Port":
case "Sent":
case "Received":
case "SentCommands":
case "ReceivedCommands":
e.SortResult = ((long)connectionsDataGridView.Rows[e.RowIndex1].Cells[e.Column.Name].Tag + ((RandomTag<IPAddress>)connectionsDataGridView.Rows[e.RowIndex1].Tag).SortTag).CompareTo((long)connectionsDataGridView.Rows[e.RowIndex2].Cells[e.Column.Name].Tag + ((RandomTag<IPAddress>)connectionsDataGridView.Rows[e.RowIndex2].Tag).SortTag);
e.Handled = true;
break;
}
}
示例14: dataGridViewUpdates_SortCompare
private void dataGridViewUpdates_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
Alert alert1 = (Alert)dataGridViewUpdates.Rows[e.RowIndex1].Tag;
Alert alert2 = (Alert)dataGridViewUpdates.Rows[e.RowIndex2].Tag;
if (e.Column.Index == ColumnMessage.Index)
{
e.SortResult = Alert.CompareOnTitle(alert1, alert2);
e.Handled = true;
}
else if (e.Column.Index == ColumnReleaseDate.Index)
{
e.SortResult = Alert.CompareOnDate(alert1, alert2);
e.Handled = true;
}
else if (e.Column.Index == ColumnWebPage.Index)
{
e.SortResult = Alert.CompareOnWebPage(alert1, alert2);
e.Handled = true;
}
else if (e.Column.Index == ColumnAppliesTo.Index)
{
e.SortResult = Alert.CompareOnAppliesTo(alert1, alert2);
e.Handled = true;
}
}
示例15: dgvMethod_SortCompare
private void dgvMethod_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
if (e.CellValue1 != null && e.CellValue2 != null)
{
string valueString1 = e.CellValue1.ToString();
string valueString2 = e.CellValue2.ToString();
if (e.Column.Name.Equals("ColCodeNum"))
{
float value1 = 0f;
float value2 = 0f;
float.TryParse(valueString1, out value1);
float.TryParse(valueString2, out value2);
e.SortResult = Comparer.DefaultInvariant.Compare(value1, value2);
}
else
{
e.SortResult = string.Compare(valueString1, valueString2);
}
}
e.Handled = true;
}