本文整理汇总了C#中System.Windows.Forms.DataGridView.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.Sort方法的具体用法?C# DataGridView.Sort怎么用?C# DataGridView.Sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.Sort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeGrid
/// ------------------------------------------------------------------------------------
public void InitializeGrid(DataGridView grid)
{
foreach (var col in Columns)
{
if (!grid.Columns.Contains(col.Id))
continue;
grid.Columns[col.Id].Visible = col.Visible;
if (col.Width >= 0)
grid.Columns[col.Id].Width = col.Width;
if (col.DisplayIndex < 0)
grid.Columns[col.Id].DisplayIndex = 0;
else if (col.DisplayIndex >= grid.ColumnCount)
grid.Columns[col.Id].DisplayIndex = grid.ColumnCount - 1;
else
grid.Columns[col.Id].DisplayIndex = col.DisplayIndex;
}
if (!string.IsNullOrEmpty(SortedColumn) && grid.Columns.Contains(SortedColumn))
grid.Sort(grid.Columns[SortedColumn], SortOrder == SortOrder.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending);
// If the column header height or the former dpi settings are different,
// then auto. calculate the height of the column headings.
if (ColumnHeaderHeight <= 0 || DPI != m_currDpi)
grid.AutoResizeColumnHeadersHeight();
else
grid.ColumnHeadersHeight = ColumnHeaderHeight;
}
示例2: DataGridSort
public static void DataGridSort(DataGridView dgv, int column)
{
DataGridViewCustomSorter dgvSorter = null;
if (dgv.Tag == null || !(dgv.Tag is IComparer))
{
dgvSorter = new DataGridViewCustomSorter(dgv);
dgv.Tag = dgvSorter;
}
else
{
dgvSorter = (DataGridViewCustomSorter)dgv.Tag;
}
dgvSorter.SortColumn = column;
dgv.Sort(dgvSorter);
}
示例3: AddDataToGrid
public void AddDataToGrid(DataGridView _messageGridView)
{
SqlCeConnection conn = new SqlCeConnection(
Properties.Settings.Default.SIM900ConnectionString);
conn.Open();
using (SqlCeDataAdapter adapter = new SqlCeDataAdapter(
"SELECT * FROM MessageTable", conn))
{
DataSet dataSource = new DataSet();
adapter.Fill(dataSource, "Message_table");
_messageGridView.DataSource = dataSource;
_messageGridView.DataMember = "Message_table";
_messageGridView.Sort(_messageGridView.Columns[1], ListSortDirection.Descending);
}
conn.Close();
}
示例4: LoadGrid
void LoadGrid(DataGridView grid, Dictionary<int, int> stats)
{
grid.Rows.Clear();
grid.Columns.Clear();
grid.Columns.Add("Total", "Total");
grid.Columns.Add("Count", "Count");
foreach (int total in stats.Keys)
{
int rowIndex = grid.Rows.Add();
grid[0, rowIndex].Value = total;
grid[1, rowIndex].Value = stats[total];
grid.Rows[rowIndex].Tag = total;
PaintRow(grid, rowIndex);
}
grid.Sort(grid.Columns[0], ListSortDirection.Ascending);
}
示例5: MoverFilas
private void MoverFilas(DataGridView origen, DataGridView destino)
{
foreach (DataGridViewRow fila in origen.SelectedRows)
{
destino.Rows.Add(fila.Cells[0].Value, fila.Cells[1].Value);
origen.Rows.Remove(fila);
}
destino.Sort(destino.Columns[1], ListSortDirection.Ascending);
}
示例6: actualizarNuevosValores_trueFalse
private void actualizarNuevosValores_trueFalse(DataGridView dgv)
{
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.ProgressChanged += new ProgressChangedEventHandler(actualizarPorcentajeQuery);
int tipo = int.Parse(tb2_txtTipo.Text);
int var = int.Parse(tb2_txtVar.Text);
OleDbCommand comm = new OleDbCommand();
comm.Connection = conexion;
string field = "";
foreach (DataGridViewRow row in tb2_dgv.Rows)
{
field = row.Cells[0].Value.ToString();
if (Convert.ToBoolean(row.Cells[2].Value) == true)
{
comm.CommandText = "UPDATE tCampos SET " + field + " = TRUE WHERE TipoEtiqueta=" + tipo + " AND varEtiqueta = " + var + "";
try
{
conexion.Open();
comm.ExecuteNonQuery();
conexion.Close();
}
catch (Exception ex)
{
if (conexion.State == ConnectionState.Open)
conexion.Close();
MessageBox.Show(ex.Message);
return;
}
}
else
{
comm.CommandText = "UPDATE tCampos SET " + field + " = FALSE WHERE TipoEtiqueta=" + tipo + " AND varEtiqueta = " + var + "";
try
{
conexion.Open();
comm.ExecuteNonQuery();
conexion.Close();
}
catch (Exception ex)
{
if (conexion.State == ConnectionState.Open)
conexion.Close();
MessageBox.Show(ex.Message);
return;
}
}
worker.ReportProgress(row.Index + 1);
}
try
{
comm.CommandText = "UPDATE tCampos SET EtiquetasPorHoja = " + int.Parse(tb2_cmbEtqHoja.Text.ToString())
+ " WHERE TipoEtiqueta = "+tipo+" AND varEtiqueta = "+var+"";
conexion.Open();
comm.ExecuteNonQuery();
conexion.Close();
conexion.Open();
comm.CommandText = "UPDATE tCampos SET TipoCodigoBarra = "+int.Parse(tb2_cmbTipoCod.Text)
+ " WHERE TipoEtiqueta = " + tipo + " AND varEtiqueta = " + var + "";
comm.ExecuteNonQuery();
conexion.Close();
conexion.Open();
comm.CommandText = "UPDATE tIdiomasEtiquetas SET idiomaEtiqueta=" + (tb2_cmbIdiomaEtq.SelectedIndex + 1)
+ " WHERE tipoEtiqueta = '" + tipo + "' AND variacionEtiqueta = '" + var + "'";
comm.ExecuteNonQuery();
conexion.Close();
conexion.Open();
comm.CommandText = "UPDATE tNombresLotes SET LoteDespacho='" + tb2_txtLoteDesp.Text
+ "' WHERE tipo = " + tipo + " AND var = " + var + "";
comm.ExecuteNonQuery();
conexion.Close();
conexion.Open();
comm.CommandText = "UPDATE tNombresLotes SET LoteProduccion='" + tb2_txtLoteProd.Text
+ "' WHERE tipo = " + tipo + " AND var = " + var + "";
comm.ExecuteNonQuery();
conexion.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
MessageBox.Show("Se actualizaron los campos para la etiqueta tipo " + tipo.ToString() + " variación " + var + ". ", "Éxito", MessageBoxButtons.OK);
dgv.Sort(dgv.Columns[2], ListSortDirection.Descending);
foreach (DataGridViewRow row in dgv.Rows)
row.DefaultCellStyle.BackColor = Color.White;
tb2_pbar.Value = 0;
}
示例7: actualizarDGV
private void actualizarDGV(DataGridView dgv, string nuevo)
{
string[] split = nuevo.Split('|');
dgv.Rows.Add(1);
dgv.Rows[dgv.RowCount - 1].Cells[0].Value = split[0];
dgv.Rows[dgv.RowCount - 1].Cells[1].Value = split[1];
dgv.Rows[dgv.RowCount - 1].Cells[2].Value = true;
dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.BackColor = Color.LightGreen;
dgv.Columns[2].SortMode = DataGridViewColumnSortMode.Automatic;
dgv.Sort(dgv.Columns[2], ListSortDirection.Descending);
}
示例8: setGridSort
/// <summary>
/// グリッドのソート設定
/// </summary>
/// <param name="iGrid">グリッド</param>
/// <param name="iColName">列名</param>
/// <param name="iSortOrder">ソート順</param>
private void setGridSort(DataGridView iGrid, string iColName, SortOrder iSortOrder)
{
if (iColName != string.Empty)
{
ListSortDirection sortDirection = ListSortDirection.Ascending;
if (iSortOrder == SortOrder.Ascending)
{
sortDirection = ListSortDirection.Ascending;
}
else if (iSortOrder == SortOrder.Descending)
{
sortDirection = ListSortDirection.Descending;
}
iGrid.Sort(iGrid.Columns[iColName], sortDirection);
}
}
示例9: Category3Button_Click
//.........这里部分代码省略.........
tempOrderDetails.OrderFoodType = tempFoodType == 1 ? ("Food") : ("Nonfood");
tempOrderDetails.ItemOrderTime = DateTime.Now.Ticks;
tempOrderManager.UpdateOrderDetails(tempOrderDetails);
}
else
{
//Insert into Order_details table
tempOrderDetails.OrderID = orderID;
tempOrderDetails.ProductID = tempCategory4Button.CategoryID;
tempOrderDetails.CategoryLevel = tempCategory4Button.CategoryLevel;
tempOrderDetails.OrderQuantity = m_iSavedOrderedQty;
tempOrderDetails.OrderAmount = tempOrderDetails.OrderQuantity * Double.Parse(tableTypePrice);
tempOrderDetails.ItemOrderTime = DateTime.Now.Ticks;
tempOrderDetails.OrderFoodType = tempFoodType == 1 ? ("Food") : ("Nonfood");
CResult oResult = tempOrderManager.InsertOrderDetails(tempOrderDetails);
if (oResult.IsSuccess && oResult.Data != null)
{
tempOrderDetails = (COrderDetails)oResult.Data;
}
string[] tempDataGridViewRow = new string[]
{ ItemName,
m_iSavedOrderedQty.ToString(),
((double)(Double.Parse(tableTypePrice)*m_iSavedOrderedQty)).ToString("F02"),
tempCategory4Button.CategoryID.ToString(),
"4",
temp2DataRowArray[0]["cat4_rank"].ToString(),
tempOrderDetails.OrderDetailsID.ToString()
};
tempDataGridView.Rows.Add(tempDataGridViewRow);
}
ConvertRank();
tempDataGridView.Sort(tempDataGridView.Columns[5], ListSortDirection.Ascending);
tempDataGridView.Update();
TotalAmountCalculation();
}
}
}
else //There is no category4
{
NewOrder();
DataGridViewRow tempDataGridViewRow = new DataGridViewRow();
tempDataGridViewRow.CreateCells(tempDataGridView);
DataRow[] temp2DataRowArray = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCategory3Button.CategoryID.ToString());
if (temp2DataRowArray.Length != 0)
{
string tableTypePrice = string.Empty;
tableTypePrice = temp2DataRowArray[0]["bar_price"].ToString();
COrderManager tempOrderManager = new COrderManager();
COrderDetails tempOrderDetails = new COrderDetails();
int tempResult = DataGridViewSearch(tempDataGridView, temp2DataRowArray[0]["cat3_name"].ToString());
if (tempResult != -1)
{
//update Order_details table
int tempRowIndex = tempResult;
int qty=int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[1].Value.ToString()) + m_iSavedOrderedQty;
tempDataGridView.Rows[tempRowIndex].Cells[1].Value = qty;
tempDataGridView.Rows[tempRowIndex].Cells[2].Value = ((double)(Double.Parse(tableTypePrice) * qty)).ToString("F02");
tempOrderDetails.OrderDetailsID = Int64.Parse(tempDataGridView.Rows[tempRowIndex].Cells[6].Value.ToString());
tempOrderDetails.OrderID = orderID;
tempOrderDetails.ProductID = tempCategory3Button.CategoryID;
示例10: ShowTags_Click
internal static void ShowTags_Click(object sender, EventArgs e, User i_LoggedInUser, DataGridView i_dataGridViewFriends)
{
i_dataGridViewFriends.Rows.Clear();
i_dataGridViewFriends.Tag = k_PhotosGridTag;
i_dataGridViewFriends.Columns[0].HeaderText = k_NameColumnHeader;
i_dataGridViewFriends.Columns[1].HeaderText = k_SharedPhotosColumnHeader;
i_dataGridViewFriends.Columns[2].Visible = false;
Dictionary<string, UserRank<Photo>> allUsersWithTagsOnPhotos = FetchTags(i_LoggedInUser);
foreach (UserRank<Photo> userDetails in allUsersWithTagsOnPhotos.Values)
{
int index = i_dataGridViewFriends.Rows.Add(userDetails.Name, userDetails.GetObjectCount(), userDetails);
i_dataGridViewFriends.Rows[index].ReadOnly = true;
}
i_dataGridViewFriends.Sort(i_dataGridViewFriends.Columns[1], ListSortDirection.Descending);
}
示例11: RemoveNewRowClear
[Test] // bug #442181
public void RemoveNewRowClear ()
{
DataGridView dgv = new DataGridView ();
dgv.Columns.Add ("A", "A");
dgv.Rows.Clear ();
Assert.AreEqual (1, dgv.Rows.Count, "A1");
// This was crashing in the bug
dgv.Sort (dgv.Columns[0], ListSortDirection.Ascending);
}
示例12: fillComponents
/// <summary>
/// Refresh list of components
/// </summary>
/// <param name="grid"></param>
public void fillComponents(DataGridView grid)
{
grid.Rows.Clear();
foreach(IComponent c in bootloader.Registered)
{
Type type = c.GetType();
if(!Inspector.isComponent(type)) {
continue;
}
bool enabled = c.Enabled;
string className = c.GetType().Name;
Configuration.Component[] cfg = Settings.Cfg.Components;
if(cfg != null && cfg.Length > 0) {
Configuration.Component v = cfg.Where(p => p.ClassName == className).FirstOrDefault();
if(v != null) {
enabled = v.Enabled;
}
}
cInfo[className] = new List<INodeInfo>();
bool withoutAttr = true;
foreach(Attribute attr in type.GetCustomAttributes(true))
{
if(attr.GetType() == typeof(ComponentAttribute) || attr.GetType() == typeof(DefinitionAttribute)) {
withoutAttr = false;
}
if(attr.GetType() == typeof(ComponentAttribute) && ((ComponentAttribute)attr).Parent == null)
{
fillComponents((ComponentAttribute)attr, enabled, className, grid);
}
else if(attr.GetType() == typeof(DefinitionAttribute) && ((DefinitionAttribute)attr).Parent == null)
{
DefinitionAttribute def = (DefinitionAttribute)attr;
grid.Rows.Add(DomIcon.definition, enabled, def.Name, className, def.Description);
}
else if(((DefinitionAttribute)attr).Parent != null)
{
cInfo[className].Add(new NodeInfo((DefinitionAttribute)attr));
}
else if(((ComponentAttribute)attr).Parent != null)
{
cInfo[className].Add(new NodeInfo((ComponentAttribute)attr));
}
}
if(withoutAttr) {
grid.Rows.Add(DomIcon.package, enabled, String.Empty, className, String.Empty);
}
cInfo[className].AddRange(new List<INodeInfo>(domElemsBy(className)));
}
grid.Sort(grid.Columns[2], System.ComponentModel.ListSortDirection.Descending);
}
示例13: Category3Button_Click
//.........这里部分代码省略.........
temp2DataRowArray[0]["cat4_rank"].ToString(),
tempOrderDetails.OrderDetailsID.ToString(),
"0",
tempOrderDetails.UnitPrice.ToString("F2")
};
tempDataGridView.Rows.Add(tempDataGridViewRow);
}
else //For online orders
{
tempOrderDetails.ItemName = ItemName;
tempOrderDetails = (COrderDetails)tempOrderManager.InsertOnlineOrderDetails(tempOrderDetails).Data;
string[] tempDataGridViewRow = new string[]
{ ItemName,
m_iSavedOrderedQty.ToString(),
((double)tempOrderDetails.VatTotal).ToString("F02"),
((double)(Double.Parse(tableTypePrice)*m_iSavedOrderedQty)).ToString("F02"),
tempCategory4Button.CategoryID.ToString(),
"4",
tempOrderDetails.OnlineItemSequenceNumber.ToString(),
tempOrderDetails.OrderDetailsID.ToString(),"0",
tempOrderDetails.UnitPrice.ToString("F2")
};
tempDataGridView.Rows.Add(tempDataGridViewRow);
}
}
if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) //If local orders are considered
{
this.ConvertRank();
}
tempDataGridView.Sort(tempDataGridView.Columns[5], ListSortDirection.Ascending);
tempDataGridView.Update();
TotalAmountCalculation();
}
}
}
else //There is no category4
{
keyboardForm.Hide();
try
{
CCalculatorForm tempCalculatorForm = new CCalculatorForm("Order Quantity", "Item Quantity");
tempCalculatorForm.ShowDialog();
if (CCalculatorForm.inputResult.Equals("Cancel"))
return;
string str = CCalculatorForm.inputResult;
str = (str == "") ? "1" : str;
if (Int32.Parse(str) == 0)
{
CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!");
tempMessageBox.ShowDialog();
return;
}
int tempOrderedQty = Int32.Parse(str);
m_iSavedOrderedQty = tempOrderedQty;
}
catch (Exception exp)
示例14: LoadOrderDetails
//.........这里部分代码省略.........
tempProductName+appendString,
tempOrderDetailsList[itemIndex].OrderQuantity.ToString(),
((double)tempOrderDetailsList[itemIndex].VatTotal).ToString("F02"),
((double)tempOrderDetailsList[itemIndex].OrderAmount).ToString("F02"),
tempOrderDetailsList[itemIndex].ProductID.ToString(),
tempOrderDetailsList[itemIndex].CategoryLevel.ToString(),
(Int64.MaxValue-1)+"",//max rank
tempOrderDetailsList[itemIndex].OrderDetailsID.ToString(),
tempOrderDetailsList[itemIndex].PrintedQuantity.ToString(),
tempOrderDetailsList[itemIndex].UnitPrice.ToString("F2"),
};
//not misc item... rank is specified
if (tempCategoryLevel != 0)
{
try
{
tempDataGridViewRow[6] = Program.initDataSet.Tables["Category" + tempCategoryLevel].Select("cat" + tempCategoryLevel + "_id = " + tempProductID)[0]["cat" + tempCategoryLevel + "_rank"].ToString();
}
catch { }
}
try
{
tempDataGridView.Rows.Add(tempDataGridViewRow);
}
catch (Exception ex)
{
// MessageBox.Show(ex.ToString());
}
ConvertRank();
if (tempDataGridView.Columns["Order_details_id"] !=null)
tempDataGridView.Sort(tempDataGridView.Columns["Order_details_id"], ListSortDirection.Descending);
if (tempDataGridView.Columns["dataGridViewTextBoxColumn5"] != null)
tempDataGridView.Sort(tempDataGridView.Columns["dataGridViewTextBoxColumn5"], ListSortDirection.Descending);
//this.FillCategory1OrderNumber();//New
//tempDataGridView.Sort(tempDataGridView.Columns[5], ListSortDirection.Ascending);
tempDataGridView.Update();
}
//get discount
COrderDiscount tempOrderDiscount = new COrderDiscount();
oResult = tempOrderManager.OrderDiscountGetByOrderID(orderID);
if (oResult.IsSuccess && oResult.Data != null)
{
tempOrderDiscount = (COrderDiscount)oResult.Data;
m_dDiscountAmount = Convert.ToDecimal(tempOrderDiscount.Discount.ToString("F02"));
}
}
else
{
//Loading the online orders information
//g_FoodDataGridView.RowCount = 0;
COrderManager tempOrderManager = new COrderManager();
string remarks = "";
string itemName = "";
List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>();
CResult oResult = tempOrderManager.GetOnlineOrderDetailsByOrderID(orderID);
if (oResult.IsSuccess && oResult.Data != null)
tempOrderDetailsList = (List<COrderDetails>)oResult.Data;
for (int counter = 0; counter < tempOrderDetailsList.Count; counter++)
{
remarks = tempOrderDetailsList[counter].OrderRemarks.ToString();
示例15: ReDrawEveryThing
private void ReDrawEveryThing(DataTable dt, DataGridView dgv, ComboBox cmb)
{
dgv.DataSource = dt;
dgv.Columns[0].Width = dgv.Width - 75;
dgv.Sort(dgv.Columns[0], System.ComponentModel.ListSortDirection.Ascending);
cmb.Items.Clear();
cmb.Sorted = true;
cmb.Items.Add(".: انتخاب گالري مورد نظر :.");
string[] items = new string[dt.Rows.Count];
for (int i = 0; i < items.Length; i++)
items[i] = dt.Rows[i][0].ToString().Trim();
cmb.Items.AddRange(items);
cmb.SelectedIndex = 0;
}