本文整理汇总了C#中System.Windows.Forms.DataGridView.ClearSelection方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.ClearSelection方法的具体用法?C# DataGridView.ClearSelection怎么用?C# DataGridView.ClearSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.ClearSelection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IniDropDownList
public static void IniDropDownList(DataGridView dgw, string dbtype, string filetype)
{
dgw.AutoGenerateColumns = false;
dgw.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dgw.Columns[dgw.ColumnCount - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
MySqlDataContext db = MySqlHelper.DataContext;
var res = from tmp in db.CfGTemplate
select tmp;
if (dbtype != "")
{
res = res.Where(x => x.DbType == dbtype);
}
if (filetype != "")
{
res = res.Where(x => x.FileType.Contains(filetype));
}
List<tmpinfo> ztlist = (from tmp in res
select new tmpinfo() { Id = tmp.ID, Name = tmp.Name, Dbtype = tmp.DbType, Filetype = tmp.FileType, Path = tmp.Path }).ToList<tmpinfo>();
if (filetype.IndexOf("xls") >= 0)
{
ztlist.Insert(0, new tmpinfo() { Id = 0, Name = "新建模板", Dbtype = dbtype, Filetype = "xls|xlsx", Path = "" });
}
dgw.DataSource = ztlist;
dgw.Parent.Height = dgw.Rows.Count * dgw.RowTemplate.Height + dgw.ColumnHeadersHeight + 8;
dgw.ClearSelection();
}
示例2: Grid
public void Grid(ref DataGridView grid, DataTable dt, bool codigoVisible, bool clearSelection, bool autoSizeColumnMode)
{
try
{
grid.AutoGenerateColumns = false;
grid.MultiSelect = false;
grid.ReadOnly = true;
grid.Columns[1].Visible = codigoVisible;
grid.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
grid.DataSource = dt;
if (autoSizeColumnMode)
{
int i;
for (i = 0; i <= grid.ColumnCount - 1; i++)
{
grid.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
}
}
if (clearSelection)
{
grid.ClearSelection();
}
}
catch
{
}
}
示例3: initialiseTable
private void initialiseTable()
{
if (this.table != null) this.Controls.Remove(this.table);
table = new DataGridView();
table.Dock = DockStyle.Fill;
table.Size = new Size(this.Size.Width, this.Size.Height);
table.RowHeadersVisible = false;
table.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
table.MultiSelect = false;
table.AllowUserToAddRows = false;
table.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
String stm = "SELECT name, code, credits FROM Modules WHERE year = @year";
SQLiteDataAdapter adapt = new SQLiteDataAdapter(stm, DBSchema.connection());
adapt.SelectCommand.Parameters.Add(new SQLiteParameter("@year", year));
DataSet ds = new DataSet();
adapt.Fill(ds, "Modules");
table.DataSource = ds.Tables["Modules"];
this.Controls.Add(table);
stm = "SELECT * FROM Modules WHERE year = @year";
SQLiteCommand command = new SQLiteCommand(stm, DBSchema.connection());
command.Parameters.Add(new SQLiteParameter("@year", year));
SQLiteDataReader dr = command.ExecuteReader();
modules = new List<Module>();
while (dr.Read())
{
modules.Add(new Module(dr));
}
table.ClearSelection();
table.CellClick += new DataGridViewCellEventHandler(this.rowSelected);
}
示例4: searchFunction
public void searchFunction(DataGridView dg1,TextBox txt)
{
dg1.ClearSelection();
try
{
dg1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
foreach (DataGridViewRow row in dg1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.Value.ToString().Equals(txt.Text.Trim().ToString()) && txt.Text != "")
{
row.Selected = true;
}
}
}
}
catch (Exception exp)
{
Console.WriteLine(exp.ToString());
}
}
示例5: ResetSelect
public static void ResetSelect(DataGridView dgv)
{
if (dgv.Rows.Count > 0)
{
dgv.ClearSelection();
dgv.Rows[0].Selected = true;
dgv.CurrentCell = dgv.Rows[0].Cells[0];
}
}
示例6: customizationDataGridView
public static void customizationDataGridView(DataGridView dgv)
{
dgv.ClearSelection();
dgv.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
for (var i = 0; i < dgv.ColumnCount; i++)
{
dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
dgv.Columns[i].FillWeight = 1;
}
}
示例7: GetDataGrid
private DataGridView GetDataGrid()
{
var dgv = new DataGridView()
{
BackgroundColor = Color.White,
Location = new Point(Location.X + 5, Location.Y),
RowHeadersVisible = false,
Anchor = AnchorStyles.Top,
ScrollBars = ScrollBars.None,
AllowUserToResizeColumns = false,
AllowUserToAddRows = false,
AllowUserToResizeRows = false,
AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells,
ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
};
dgv.Columns.AddRange(new DataGridViewColumn[]
{
new DataGridViewTextBoxColumn() { HeaderText = "Время", Name = "timeColumn", ReadOnly = true },
new DataGridViewTextBoxColumn() { HeaderText = "Тип", Name = "severityColumn", ReadOnly = true },
new DataGridViewTextBoxColumn() { HeaderText = "Сообщение", Name = "messageColumn", ReadOnly = true }
});
dgv.SelectionChanged += (s, e) => dgv.ClearSelection();
for (int i = 0; i < dgv.Columns.Count; i++)
{
dgv.Columns[i].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
dgv.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
if (i == dgv.Columns.Count - 1)
{
dgv.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
//dgv.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter;
return dgv;
}
示例8: InitDataGridView
public static void InitDataGridView(DataGridView dgv)
{
//只读属性设置
//dgv.ReadOnly = true;
//尾行自动追加
dgv.AllowUserToAddRows = false;
dgv.AllowUserToDeleteRows = false;
//行幅自动变化
dgv.AllowUserToResizeRows = true;
//高度设定
dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
//标头设定
dgv.RowHeadersVisible = true;
//标题行高
dgv.ColumnHeadersHeight = 25;
dgv.RowTemplate.Height = 23;
//行选择设定
dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
//多行选择
dgv.MultiSelect = false;
//选择状态解除
dgv.ClearSelection();
//head文字居中
dgv.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
//选择状态的行的颜色
dgv.DefaultCellStyle.SelectionBackColor = Color.LightSteelBlue;
dgv.DefaultCellStyle.SelectionForeColor = Color.Black;
//设定交替行颜色
dgv.AlternatingRowsDefaultCellStyle.BackColor = Color.White;
dgv.RowsDefaultCellStyle.BackColor = Color.LightGray;
//行副填充时自动调整宽度
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
dgv.AutoGenerateColumns = false;
//可否手动调整行大小
dgv.AllowUserToResizeRows = false;
dgv.AutoGenerateColumns = false;
dgv.ScrollBars = ScrollBars.Both;
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
}
示例9: DoRowSelection
/// <summary>
/// Selects a given row in a DataGridView. If the requested row does not
/// exist, selects a suitable alternative.
/// </summary>
/// <param name="dataGridView">The DataGridView containing the row</param>
/// <param name="row">The row to select</param>
public static void DoRowSelection(DataGridView dataGridView, int row)
{
if (dataGridView.Rows.Count > 0)
{
dataGridView.ClearSelection();
if (row > -1)
{
if (row < dataGridView.Rows.Count)
{
dataGridView.Rows[row].Selected = true;
}
else
{
dataGridView.Rows[dataGridView.Rows.Count - 1].Selected = true;
}
}
else
{
dataGridView.Rows[0].Selected = true;
}
}
}
示例10: Individual_Unit_Details_Panel
public Individual_Unit_Details_Panel()
{
InitializeComponent();
this.HideOnClose = true;
this.Text = "Individual Unit Details";
this.TabText = "Individual Unit Details";
this.ToolTipText = "Individual unit information";
m_oArmorDisplayDataGrid = new DataGridView();
m_oArmorDisplayDataGrid.Dock = DockStyle.Fill;
m_oArmorDisplayDataGrid.AllowUserToAddRows = false;
m_oArmorDisplayDataGrid.AllowUserToDeleteRows = false;
m_oArmorDisplayDataGrid.AllowUserToOrderColumns = false;
m_oArmorDisplayDataGrid.AllowUserToResizeColumns = false;
m_oArmorDisplayDataGrid.AllowUserToResizeRows = false;
m_oArmorDisplayDataGrid.Enabled = true;
m_oArmorDisplayDataGrid.ReadOnly = true;
m_oArmorDisplayDataGrid.ColumnHeadersVisible = false;
m_oArmorDisplayDataGrid.RowHeadersVisible = false;
m_oArmorDisplayDataGrid.ClearSelection();
this.m_oArmorGroupBox.Controls.Add(m_oArmorDisplayDataGrid);
}
示例11: updateTables
public static void updateTables(DataGridView registerTable, DataGridView memoryTable, Cpu cpu, Main comInterface)
{
registerTable.DataSource = null;
registerTable.RowTemplate.Height = 16;
registerTable.DataSource = TableFactory.getRegisterTable(cpu);
dataGridHelper.showChanged(registerTable);
memoryTable.DataSource = null;
memoryTable.RowTemplate.Height = 16;
memoryTable.DataSource = TableFactory.getMemoryTable(comInterface.Host);
int curRow = (int) Math.Floor((double) (cpu.PC/0x10)), curCell = (cpu.PC%0x10) + 1;
if (memoryTable.ColumnCount == 0x10 + 1)
{
memoryTable.CurrentCell = memoryTable.Rows[curRow].Cells[curCell];
memoryTable.ClearSelection();
}
memoryTable.Rows[curRow].Cells[curCell].Style.BackColor = Color.Yellow;
if (lastCell != null) lastCell.Style = lastRow.DefaultCellStyle;
lastRow = memoryTable.Rows[curRow];
lastCell = lastRow.Cells[curCell];
}
示例12: DataGrid_Up_button
// =================================================================================
// Scrolling & arranging datagridviews...
// =================================================================================
private void DataGrid_Up_button(DataGridView Grid)
{
int row = Grid.CurrentCell.RowIndex;
int col = Grid.CurrentCell.ColumnIndex;
if (row == 0)
{
return;
}
if (Grid.SelectedCells.Count != 1)
{
return;
}
DataGridViewRow temp = Grid.Rows[row];
Grid.Rows.Remove(Grid.Rows[row]);
Grid.Rows.Insert(row - 1, temp);
Grid.ClearSelection();
Grid.CurrentCell = Grid[col, row - 1];
HandleGridScrolling(true, Grid);
}
示例13: SetSelectedItemDataGridView
private static void SetSelectedItemDataGridView(IBindingMemberInfo bindingMemberInfo, DataGridView dataGridView, object item)
{
dataGridView.ClearSelection();
if (item == null)
return;
for (int i = 0; i < dataGridView.Rows.Count; i++)
{
if (Equals(dataGridView.Rows[i].DataBoundItem, item))
{
var row = dataGridView.Rows[i];
row.Selected = true;
if (row.Cells.Count > 0)
row.Cells[0].Selected = true;
break;
}
}
}
示例14: FormAsignarHab_Load
private void FormAsignarHab_Load(object sender, EventArgs e)
{
int altoFilaExtraMedioPagos;
tabla1 = TablaTurnos.nuevaTabla();
tabla2 = TablaTurnos.nuevaTabla();
tabla1.DefaultCellStyle.BackColor = Color.White;
tabla2.DefaultCellStyle.BackColor = Color.White;
tabla2.Columns[8].Visible = tabla1.Columns[8].Visible = true;
this.tableLayoutPanel3.Controls.Add(tabla1, 0, 0);
int altoFila;
int altoFilaExtra;
tools.calcularAlturas(tabla1.Height - tabla1.ColumnHeadersHeight, fPrincipal2.maxFilas, out altoFila, out altoFilaExtra);
tabla1.RowTemplate.Height = altoFila;
tabla2.RowTemplate.Height = altoFila;
tabla1.ColumnHeadersHeight = tabla1.ColumnHeadersHeight + altoFilaExtra;
tabla2.ColumnHeadersHeight = tabla1.ColumnHeadersHeight;
float tamFuente = 10f + (3.6f - (0.1f * cantHab));
tabla1.DefaultCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", tamFuente, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
tabla2.DefaultCellStyle.Font = tabla1.DefaultCellStyle.Font;
this.tableLayoutPanel3.Controls.Add(tabla2, 1, 0);
tools.actualizarListadoTurnos(tabla1, tabla2);
tabla1.Columns.RemoveAt(7);
tabla1.Columns.RemoveAt(6);
tabla2.Columns.RemoveAt(7);
tabla2.Columns.RemoveAt(6);
tools.calcularAlturas(dgvOpciones.Height - dgvOpciones.ColumnHeadersHeight, opcionesCambEst.opcionesCambioEstado.Count > tools.minCantFilas ? opcionesCambEst.opcionesCambioEstado.Count : tools.minCantFilas, out altoFila, out altoFilaExtraMedioPagos);
dgvOpciones.RowTemplate.Height = altoFila;
this.opcionesCambioEstadoTableAdapter.Fill(this.opcionesCambEst.opcionesCambioEstado);
dgvOpciones.DataSource = null;
foreach (DataRow dr in opcionesCambEst.opcionesCambioEstado)
{
dOpciones.Add(int.Parse(dr[0].ToString()), dr[1].ToString());
dgvOpciones.Rows.Add(dr[0].ToString(), dr[1].ToString());
}
// ---- Completando la tabla mediosPagos ----//
tools.completarDG(dgvOpciones, altoFilaExtraMedioPagos);
dgvOpciones.ClearSelection();
tabla1.ClearSelection();
tabla2.ClearSelection();
}
示例15: dibujar
//.........这里部分代码省略.........
}
else if (reader["estado"].ToString() == "A") // Asignada
{
tabla1.Rows[ultFila].Cells["estado"].Value = "A";
tabla1.Rows[ultFila].DefaultCellStyle.Font = new Font(tabla1.DefaultCellStyle.Font, FontStyle.Bold);
//Si hay alarmas
if (reader["aviso"].ToString() != "")
tabla1.Rows[ultFila].Cells["alarma"].Value = ((System.Drawing.Image)Resources.relojdespertador);
tabla1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Green;
}
else if (reader["estado"].ToString() == "O") // Ocupada
{
tabla1.Rows[ultFila].Cells["estado"].Value = "O";
tabla1.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);
tabla1.Rows[ultFila].DefaultCellStyle.Font = new Font(tabla1.DefaultCellStyle.Font, FontStyle.Bold);
tabla1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Tomato;
if (reader["aviso"].ToString() != "")
tabla1.Rows[ultFila].Cells["alarma"].Value = ((System.Drawing.Image)Resources.relojdespertador);
}
else if (reader["estado"].ToString() == "M") // Mucama
{
tabla1.Rows[ultFila].Cells["estado"].Value = "M"; // Mucama
tabla1.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);
tabla1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Yellow;
}
else // Otro...
{
//tabla1.Rows[ultFila].DefaultCellStyle.BackColor = Color.Gainsboro;
tabla1.Rows[ultFila].Cells["estado"].Value = "X"; // deshabilitado
tabla1.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.vacio);
tabla1.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Gainsboro;
}
}
if (cantHab > maxFilas)
{
ultFila = 0;
tabla2 = TablaTurnos.nuevaTabla();
tabla2.DefaultCellStyle.BackColor = Color.White;
tabla2.Columns[8].Visible = true;
tabla2.Columns.RemoveAt(7);
tabla2.Columns.RemoveAt(6);
tabla2.DefaultCellStyle.Font = tabla1.DefaultCellStyle.Font;
tabla2.ColumnHeadersHeight = tabla1.ColumnHeadersHeight;
tabla2.RowTemplate.Height = tabla1.RowTemplate.Height;
this.tableLayoutPanel3.Controls.Add(tabla2, 1, 0);
while (reader.Read() && ultFila < 24)
{
DataGridViewRow row = new DataGridViewRow();
tabla2.Rows.Add(reader["nroHabitacion"], reader["categoria"]);
ultFila = tabla2.Rows.GetLastRow(DataGridViewElementStates.None);
if (reader["estado"].ToString() == "D")
{
tabla2.Rows[ultFila].Cells["estado"].Value = "D";
tabla2.Rows[ultFila].Cells["bar"].Value = ((System.Drawing.Image)Resources.vacio);
tabla2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Green;
}
else if (reader["estado"].ToString() == "A")
{
tabla2.Rows[ultFila].Cells["estado"].Value = "A";
tabla2.Rows[ultFila].DefaultCellStyle.Font = new Font(tabla1.DefaultCellStyle.Font, FontStyle.Bold);
//Si hay alarmas
if (reader["aviso"].ToString() != "")
tabla2.Rows[ultFila].Cells["alarma"].Value = ((System.Drawing.Image)Resources.relojdespertador);
tabla2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Green;
}
else if (reader["estado"].ToString() == "O") // Ocupada
{
tabla2.Rows[ultFila].Cells["estado"].Value = "O";
tabla2.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);
tabla2.Rows[ultFila].DefaultCellStyle.Font = new Font(tabla2.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold);
tabla2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Tomato;
if (reader["aviso"].ToString() != "")
tabla2.Rows[ultFila].Cells["alarma"].Value = ((System.Drawing.Image)Resources.relojdespertador);
}
else if (reader["estado"].ToString() == "M") // Mucama
{
tabla2.Rows[ultFila].Cells["estado"].Value = "M"; // Mucama
tabla2.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.luzOn);
tabla2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Yellow;
}
else // Otro...
{
//tabla2.Rows[ultFila].DefaultCellStyle.BackColor = Color.Gainsboro;
tabla2.Rows[ultFila].Cells["estado"].Value = "X"; // deshabilitado
tabla2.Rows[ultFila].Cells["luz"].Value = ((System.Drawing.Image)Resources.vacio);
tabla2.Rows[ultFila].Cells["nroHab"].Style.BackColor = Color.Gainsboro;
}
}
tabla2.ClearSelection();
}
tabla1.ClearSelection();
reader.Close();
}