本文整理汇总了C#中System.Windows.Forms.DataGridView.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.Focus方法的具体用法?C# DataGridView.Focus怎么用?C# DataGridView.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.Focus方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RowIdentical
/// <summary>
/// 行一致离开
/// </summary>
/// <param name="dataGridView"></param>
/// <returns></returns>
public bool RowIdentical(DataGridView dataGridView)
{
//dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
List<object> objListNull = new List<object>();
List<object> objListNotNull = new List<object>();
foreach (DataGridViewRow row in dataGridView.Rows)
{
if (!row.IsNewRow)
{
for (int i = 0; i < row.Cells.Count; i++)
{
if (row.Cells[i].Value == null || row.Cells[i].Value.ToString().Trim() == string.Empty)
{
objListNull.Add(row.Cells[i].Value);
}
else
{
objListNotNull.Add(row.Cells[i].Value);
}
}
}
if (objListNull.Count != 0 && objListNotNull.Count != 0)
{
MessageBox.Show("未完成数据表格数据,请完成数据或清空。");
foreach (DataGridViewCell item in row.Cells)
{
if (item.Value == null)
{
dataGridView.Focus();
dataGridView.CurrentCell = item;
}
}
return false;
}
}
return true;
}
示例2: RowIdentical
/// <summary>
/// 行一致离开
/// </summary>
/// <param name="dataGridView"></param>
/// <returns></returns>
private static bool RowIdentical(DataGridView dataGridView)
{
//add by dwq 2015-05-27 先提交最后一次输入DataGridView的数据
if (dataGridView.IsCurrentCellDirty)
{
dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
List<object> objListNull = new List<object>();
List<object> objListNotNull = new List<object>();
foreach (DataGridViewRow row in dataGridView.Rows)
{
if (!row.IsNewRow)
{
for (int i = 0; i < row.Cells.Count; i++)
{
if (row.Cells[i].Value == null || row.Cells[i].Value.ToString().Trim() == string.Empty)
{
objListNull.Add(row.Cells[i].Value);
}
else
{
objListNotNull.Add(row.Cells[i].Value);
}
}
}
if (objListNull.Count != 0 && objListNotNull.Count != 0)
{
TipForm tip = new TipForm(dataGridView, "请完整填写当前表格整行数据");
tip.Show();
if (!dataGridView.Parent.Focused)
{
dataGridView.Parent.Focus();
}
dataGridView.Focus();
//Form frm = UtilClass.SearchOwner(dataGridView) as Form;
//frm.Activate();
foreach (DataGridViewCell item in row.Cells)
{
if (item.Value == null)
{
dataGridView.Focus();
dataGridView.CurrentCell = item;
}
}
return false;
}
}
return true;
}
示例3: poner_combobox
public static void poner_combobox(BindingSource bs, DataGridView dgv, string celda)
{
DataRowView view = (DataRowView)bs.Current;
dgv.Rows[dgv.Rows.Count - 1].Cells[celda].Value = view["id"].ToString();
dgv.Focus();
}
示例4: ShowArticleInfo
//DataInfo
/// <summary>
/// Create short information about selected article
/// </summary>
/// <param name="grid1">Table of cheque</param>
/// <param name="grid2">Table of all articles</param>
/// <returns>Return short information about selected article. If no selected article it's return empty string.</returns>
public static string ShowArticleInfo(DataGridView grid1, DataGridView grid2)
{
string id = "";
string name = "";
string price = "";
string unit = "";
string bc = "";
if (!grid1.Focused && !grid2.Focused)
grid2.Focus();
if (grid1.Focused && grid1.Rows.Count != 0 && grid1.SelectedRows.Count != 0)
{
id = grid1.SelectedRows[0].Cells["ID"].Value.ToString();
name = grid1.SelectedRows[0].Cells["NAME"].Value.ToString();
price = grid1.SelectedRows[0].Cells["PRICE"].Value.ToString();
unit = grid1.SelectedRows[0].Cells["UNIT"].Value.ToString();
bc = grid1.SelectedRows[0].Cells["BC"].Value.ToString();
return id + " " + name + " : Ціна " + price + " за 1" + unit + " Штрих-код : " + bc;
}
if (grid2.Focused && grid2.Rows.Count != 0 && grid2.SelectedRows.Count != 0)
{
id = grid2.SelectedRows[0].Cells["ID"].Value.ToString();
name = grid2.SelectedRows[0].Cells["NAME"].Value.ToString();
price = grid2.SelectedRows[0].Cells["PRICE"].Value.ToString();
unit = grid2.SelectedRows[0].Cells["UNIT"].Value.ToString();
bc = grid2.SelectedRows[0].Cells["BC"].Value.ToString();
return id + " " + name + " : Ціна " + price + " за 1" + unit + " Штрих-код : " + bc;
}
return "";
}
示例5: inserta_persona
// el Bs de persona, el bs del elemento a tratar, el dgv del elemento a tratar
// el maximo del id de el elemento a tratar
// el elemnto donde quiro pararme al adicionar un elemento(nombre)
// el nombre del id que tiene el dgv a tratar(id)
// el nombre q tiene id id perosna en la tabla especifica
public static void inserta_persona(BindingSource persona, BindingSource bs, DataGridView dgv, int max, string nombre, string id, string id_detalle)
{
if (dgv.Rows.Count > 0) dgv.CurrentCell = dgv.CurrentRow.Cells[nombre];
if (max >= 10000) max = max + 1;
else max = Convert.ToInt32(Convert.ToString(mia.id_centro) + "0001");
bs.AddNew();
dgv.Rows[dgv.Rows.Count - 1].Cells[id].Value = max;
dgv.CurrentCell = dgv.CurrentRow.Cells[nombre];
DataRowView view = (DataRowView)persona.Current;
dgv.Rows[dgv.Rows.Count - 1].Cells[id_detalle].Value = view["id"].ToString();
dgv.Focus();
}
示例6: validaErrorDGV
/// <summary>
/// METODO DE VALIDACION DE LA GRILLA
/// </summary>
/// <param name="grilla">datagrid view</param>
/// <param name="tex">mesaje</param>
/// <returns></returns>
private bool validaErrorDGV(DataGridView grilla,string tex)
{
if (grilla.Rows.Count==0)
{
epValida.SetError(grilla, tex);
grilla.Focus();
return false;
}
else
{
epValida.Clear();
return true;
}
}
示例7: dataGridView_Pedidos_Click
//.........这里部分代码省略.........
this.dataGridView_Historial.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView_Historial.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView_Historial.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Id_PedidoD,
this.Id_ClienteD,
this.Id_ProductoD,
this.ProductoD,
this.CantidadD});
//this.UnidadD});
this.dataGridView_Historial.Cursor = System.Windows.Forms.Cursors.Hand;
this.dataGridView_Historial.Location = new System.Drawing.Point(6, 44);
this.dataGridView_Historial.Name = "dataGridView_Historial";
this.dataGridView_Historial.Size = new System.Drawing.Size(470, 264);
this.dataGridView_Historial.TabIndex = 2;
//this.dataGridView_Historial.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.dataGridView_Historial_MouseDoubleClick);
//
// Id_PedidoD
//
this.Id_PedidoD.HeaderText = "Id_Pedido";
this.Id_PedidoD.Name = "Id_PedidoD";
this.Id_PedidoD.Visible = false;
//
// Id_ClienteD
//
this.Id_ClienteD.HeaderText = "Id_ClienteD";
this.Id_ClienteD.Name = "Id_ClienteD";
this.Id_ClienteD.Visible = false;
//
// Id_ProductoD
//
this.Id_ProductoD.HeaderText = "Id_Producto";
this.Id_ProductoD.Name = "Id_ProductoD";
this.Id_ProductoD.Visible = false;
//
// ProductoD
//
this.ProductoD.HeaderText = "Producto";
this.ProductoD.Name = "ProductoD";
//
// CantidadD
//
this.CantidadD.HeaderText = "Cantidad";
this.CantidadD.Name = "CantidadD";
//
// bttn_Entregarpedido_Cliente
//
this.bttn_Entregarpedido_Cliente.Location = new System.Drawing.Point(19, 319);
this.bttn_Entregarpedido_Cliente.Name = "bttn_Entregarpedido_Cliente";
this.bttn_Entregarpedido_Cliente.Size = new System.Drawing.Size(105, 23);
this.bttn_Entregarpedido_Cliente.TabIndex = 4;
this.bttn_Entregarpedido_Cliente.Text = "Entregar pedido";
this.bttn_Entregarpedido_Cliente.UseVisualStyleBackColor = true;
this.bttn_Entregarpedido_Cliente.Click += new System.EventHandler(this.bttn_Entregarpedido_Cliente_Click);
//
// bttn_Cancelarpedido_Cliente
//
this.bttn_Cancelarpedido_Cliente.BackColor = System.Drawing.Color.Red;
this.bttn_Cancelarpedido_Cliente.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.bttn_Cancelarpedido_Cliente.ForeColor = System.Drawing.Color.White;
this.bttn_Cancelarpedido_Cliente.Location = new System.Drawing.Point(343, 319);
this.bttn_Cancelarpedido_Cliente.Name = "bttn_Cancelarpedido_Cliente";
this.bttn_Cancelarpedido_Cliente.Size = new System.Drawing.Size(117, 23);
this.bttn_Cancelarpedido_Cliente.TabIndex = 5;
this.bttn_Cancelarpedido_Cliente.Text = "Cancelar pedido";
this.bttn_Cancelarpedido_Cliente.UseVisualStyleBackColor = false;
this.bttn_Cancelarpedido_Cliente.Click += new System.EventHandler(this.bttn_Cancelarpedido_Cliente_Click);
//
// bttn_CerrarPanel
//
this.bttn_CerrarPanel.BackColor = System.Drawing.Color.Red;
this.bttn_CerrarPanel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.bttn_CerrarPanel.ForeColor = System.Drawing.Color.White;
this.bttn_CerrarPanel.Location = new System.Drawing.Point(453, 1);
this.bttn_CerrarPanel.Name = "bttn_CerrarPanel";
this.bttn_CerrarPanel.Size = new System.Drawing.Size(23, 23);
this.bttn_CerrarPanel.TabIndex = 3;
this.bttn_CerrarPanel.Text = "X";
this.bttn_CerrarPanel.UseVisualStyleBackColor = false;
this.bttn_CerrarPanel.Click += new System.EventHandler(this.bttn_CerrarPanel_Click);
#endregion
#region Agreando panel al control
this.Controls.Add(this.panel1);
#endregion
#region Llenando datos
idpend = Convert.ToInt32(dataGridView_Pedidos.CurrentRow.Cells["Id_Pedido"].Value);
LLenando_PedidosClientesDetalle();
try
{
panel_PedidoClientes.Dispose(); // Libero de la memoria el panel de pedido para quitarlo
Controls.Remove(panel_PedidoClientes); // Quito el control de la ventana
Control_Historial_Clientes(); // Vuelvo a crear el control con el fin de que aparesca en la parte de atras
dataGridView_Historial.Focus();
}
catch (Exception)
{
//En caso de ocurrir un error omite la instrucción
throw;
}
#endregion
}
示例8: dataGridView_PedidosPROVEEDORES_Click
//.........这里部分代码省略.........
this.bttn_CerrarPanelProv.BackColor = System.Drawing.Color.Red;
this.bttn_CerrarPanelProv.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.bttn_CerrarPanelProv.ForeColor = System.Drawing.Color.White;
this.bttn_CerrarPanelProv.Location = new System.Drawing.Point(453, 1);
this.bttn_CerrarPanelProv.Name = "bttn_CerrarPanelProv";
this.bttn_CerrarPanelProv.Size = new System.Drawing.Size(23, 23);
this.bttn_CerrarPanelProv.TabIndex = 3;
this.bttn_CerrarPanelProv.Text = "X";
this.bttn_CerrarPanelProv.UseVisualStyleBackColor = false;
this.bttn_CerrarPanelProv.Click += new System.EventHandler(this.bttn_CerrarPanelP_Click);
//
// dataGridView_HistorialProveedor
//
this.dataGridView_HistorialProveedor.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView_HistorialProveedor.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView_HistorialProveedor.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView_HistorialProveedor.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Id_CompraP,
this.Id_Proveedor,
this.Id_ProductoP,
this.ProductoP,
this.CantidadP});
this.dataGridView_HistorialProveedor.Cursor = System.Windows.Forms.Cursors.Hand;
this.dataGridView_HistorialProveedor.Location = new System.Drawing.Point(6, 44);
this.dataGridView_HistorialProveedor.Name = "dataGridView_HistorialProveedor";
this.dataGridView_HistorialProveedor.Size = new System.Drawing.Size(470, 269);
this.dataGridView_HistorialProveedor.TabIndex = 2;
//this.dataGridView_HistorialProveedor.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.dataGridView_Historial_MouseDoubleClick);
//
// txt_Proved
//
this.txt_Proved.Enabled = false;
this.txt_Proved.Location = new System.Drawing.Point(68, 8);
this.txt_Proved.Name = "txt_Proved";
this.txt_Proved.Size = new System.Drawing.Size(225, 20);
this.txt_Proved.TabIndex = 1;
//
// lbl_Proved
//
this.lbl_Proved.AutoSize = true;
this.lbl_Proved.Location = new System.Drawing.Point(3, 11);
this.lbl_Proved.Name = "lbl_Proved";
this.lbl_Proved.Size = new System.Drawing.Size(59, 13);
this.lbl_Proved.TabIndex = 0;
this.lbl_Proved.Text = "Proveedor:";
//
// Id_CompraP
//
this.Id_CompraP.HeaderText = "Id_Compra";
this.Id_CompraP.Name = "Id_CompraP";
this.Id_CompraP.Visible = false;
//
// Id_Proveedor
//
this.Id_Proveedor.HeaderText = "Id_Proveedor";
this.Id_Proveedor.Name = "Id_Proveedor";
this.Id_Proveedor.Visible = false;
//
// Id_ProductoP
//
this.Id_ProductoP.HeaderText = "Id_Producto";
this.Id_ProductoP.Name = "Id_ProductoP";
this.Id_ProductoP.Visible = false;
//
// ProductoP
//
this.ProductoP.HeaderText = "Producto";
this.ProductoP.Name = "ProductoP";
//
// CantidadP
//
this.CantidadP.HeaderText = "Cantidad";
this.CantidadP.Name = "CantidadP";
//
// UnidadP
//
this.UnidadP.HeaderText = "Unidad";
this.UnidadP.Name = "UnidadP";
#endregion
#region Agregando el panel al control
this.Controls.Add(this.panel2);
#endregion
#region Llenando datos
idcomp = Convert.ToInt32(dataGridView_PedidosPROVEEDORES.CurrentRow.Cells["Id_PedidoProveedor"].Value);
LLenando_PedidosProveedoresDetalle();
try
{
panel_PedidoProveedores.Dispose(); // Libero de la memoria el panel de pedido para quitarlo
Controls.Remove(panel_PedidoProveedores); // Quito el control de la ventana
Control_Historial_Proveedores(); // Vuelvo a crear el control con el fin de que aparesca en la parte de atras
dataGridView_HistorialProveedor.Focus();
}
catch (Exception)
{
//En caso de ocurrir un error omite la instrucción
}
#endregion
}
示例9: Control_Historial_Proveedores
//.........这里部分代码省略.........
this.panel_PedidoProveedores.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView_PedidosPROVEEDORES)).BeginInit();
this.SuspendLayout();
#endregion
#region Agregando diseño para el panel de historial de proveedores
//
// panel_PedidoProveedores
//
this.panel_PedidoProveedores.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel_PedidoProveedores.Controls.Add(this.lbl_PedidoProveedores);
this.panel_PedidoProveedores.Controls.Add(this.bttn_CerrarPanelPROVEEDORES);
this.panel_PedidoProveedores.Controls.Add(this.dataGridView_PedidosPROVEEDORES);
this.panel_PedidoProveedores.Location = new System.Drawing.Point(100, 174);
this.panel_PedidoProveedores.Name = "panel_PedidoProveedores";
this.panel_PedidoProveedores.Size = new System.Drawing.Size(719, 387);
this.panel_PedidoProveedores.TabIndex = 1;
//
// lbl_PedidoProveedores
//
this.lbl_PedidoProveedores.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.lbl_PedidoProveedores.AutoSize = true;
this.lbl_PedidoProveedores.Location = new System.Drawing.Point(269, 9);
this.lbl_PedidoProveedores.Name = "lbl_PedidoProveedores";
this.lbl_PedidoProveedores.Size = new System.Drawing.Size(209, 13);
this.lbl_PedidoProveedores.TabIndex = 5;
this.lbl_PedidoProveedores.Text = "LISTA DE PEDIDOS DE PROVEEDORES";
this.lbl_PedidoProveedores.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// bttn_CerrarPanelPROVEEDORES
//
this.bttn_CerrarPanelPROVEEDORES.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.bttn_CerrarPanelPROVEEDORES.BackColor = System.Drawing.Color.Red;
this.bttn_CerrarPanelPROVEEDORES.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.bttn_CerrarPanelPROVEEDORES.ForeColor = System.Drawing.Color.White;
this.bttn_CerrarPanelPROVEEDORES.Location = new System.Drawing.Point(690, 3);
this.bttn_CerrarPanelPROVEEDORES.MaximumSize = new System.Drawing.Size(23, 23);
this.bttn_CerrarPanelPROVEEDORES.MinimumSize = new System.Drawing.Size(23, 23);
this.bttn_CerrarPanelPROVEEDORES.Name = "bttn_CerrarPanelPROVEEDORES";
this.bttn_CerrarPanelPROVEEDORES.Size = new System.Drawing.Size(23, 23);
this.bttn_CerrarPanelPROVEEDORES.TabIndex = 4;
this.bttn_CerrarPanelPROVEEDORES.Text = "X";
this.bttn_CerrarPanelPROVEEDORES.UseVisualStyleBackColor = false;
this.bttn_CerrarPanelPROVEEDORES.Click += new System.EventHandler(this.bttn_CerrarPanelPROVEEDORES_Click);
//
// dataGridView_PedidosPROVEEDORES
//
this.dataGridView_PedidosPROVEEDORES.AllowUserToAddRows = false;
this.dataGridView_PedidosPROVEEDORES.AllowUserToDeleteRows = false;
this.dataGridView_PedidosPROVEEDORES.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView_PedidosPROVEEDORES.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView_PedidosPROVEEDORES.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView_PedidosPROVEEDORES.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Id_PedidoProveedor,
this.Id_ProveedorP,
this.Proveedor,
this.Fecha_PedidoProveedor});
this.dataGridView_PedidosPROVEEDORES.Location = new System.Drawing.Point(3, 32);
this.dataGridView_PedidosPROVEEDORES.Name = "dataGridView_PedidosPROVEEDORES";
this.dataGridView_PedidosPROVEEDORES.ReadOnly = true;
this.dataGridView_PedidosPROVEEDORES.Size = new System.Drawing.Size(712, 350);
this.dataGridView_PedidosPROVEEDORES.TabIndex = 1;
this.dataGridView_PedidosPROVEEDORES.Click += new EventHandler(dataGridView_PedidosPROVEEDORES_Click);
//
// Id_PedidoProveedor
//
this.Id_PedidoProveedor.HeaderText = "Id_Pedido";
this.Id_PedidoProveedor.Name = "Id_PedidoProveedor";
this.Id_PedidoProveedor.ReadOnly = true;
this.Id_PedidoProveedor.Visible = false;
//
// Id_ProveedorP
//
this.Id_ProveedorP.HeaderText = "Id_Proveedor";
this.Id_ProveedorP.Name = "Id_ProveedorP";
this.Id_ProveedorP.ReadOnly = true;
this.Id_ProveedorP.Visible = false;
//
// Proveedor
//
this.Proveedor.HeaderText = "Proveedor";
this.Proveedor.Name = "Proveedor";
this.Proveedor.ReadOnly = true;
//
// Fecha_PedidoProveedor
//
this.Fecha_PedidoProveedor.HeaderText = "Fecha Pedido";
this.Fecha_PedidoProveedor.Name = "Fecha_PedidoProveedor";
this.Fecha_PedidoProveedor.ReadOnly = true;
//
// MENU PRINCIPAL
//
this.Controls.Add(this.panel_PedidoProveedores);
#endregion
LLenando_PedidosProveedores();
dataGridView_PedidosPROVEEDORES.Focus();
}