Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

Propriedade DataGridView.SelectionMode

 

Obtém ou define um valor que indica como as células do DataGridView podem ser selecionadas.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (em System.Windows.Forms.dll)

[BrowsableAttribute(true)]
public DataGridViewSelectionMode SelectionMode { get; set; }

Valor da Propriedade

Type: System.Windows.Forms.DataGridViewSelectionMode

Um dos valores de DataGridViewSelectionMode. O padrão é RowHeaderSelect.

Exception Condition
InvalidEnumArgumentException

O valor especificado ao definir essa propriedade não é um valor DataGridViewSelectionMode válido.

InvalidOperationException

O valor especificado ao definir essa propriedade é FullColumnSelect ou ColumnHeaderSelect e a propriedade SortMode de uma ou mais colunas é definida como Automatic.

Changing the value of the P:System.Windows.Forms.DataGridView.SelectionMode property clears the current selection.

The following code example demonstrates how to set the P:System.Windows.Forms.DataGridView.ColumnHeadersDefaultCellStyle, P:System.Windows.Forms.DataGridView.AutoSizeRowsMode, P:System.Windows.Forms.DataGridView.ColumnHeadersBorderStyle, P:System.Windows.Forms.DataGridView.CellBorderStyle, P:System.Windows.Forms.DataGridView.GridColor, P:System.Windows.Forms.DataGridView.BackgroundColor, P:System.Windows.Forms.DataGridView.RowHeadersVisible, P:System.Windows.Forms.DataGridView.SelectionMode, P:System.Windows.Forms.DataGridView.ColumnCount, and P:System.Windows.Forms.DataGridView.MultiSelect properties. In addition, the code example demonstrates how to set the P:System.Windows.Forms.DataGridViewColumn.Name and P:System.Windows.Forms.DataGridViewColumn.DefaultCellStyle properties. To run this example, paste the code into a form that contains a T:System.Windows.Forms.DataGridView named dataGridView1, and then call the SetUpDataGridView method from the form's constructor or E:System.Windows.Forms.Form.Load event handler. Ensure all events are associated with their event handlers.

private void SetUpDataGridView()
{
    this.Controls.Add(dataGridView1);
    dataGridView1.ColumnCount = 5;
    DataGridViewCellStyle style = 
        dataGridView1.ColumnHeadersDefaultCellStyle;
    style.BackColor = Color.Navy;
    style.ForeColor = Color.White;
    style.Font = new Font(dataGridView1.Font, FontStyle.Bold);

    dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
    dataGridView1.Name = "dataGridView1";
    dataGridView1.Location = new Point(8, 8);
    dataGridView1.Size = new Size(500, 300);
    dataGridView1.AutoSizeRowsMode = 
        DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
    dataGridView1.ColumnHeadersBorderStyle = 
        DataGridViewHeaderBorderStyle.Raised;
    dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
    dataGridView1.GridColor = SystemColors.ActiveBorder;
    dataGridView1.RowHeadersVisible = false;

    dataGridView1.Columns[0].Name = "Release Date";
    dataGridView1.Columns[1].Name = "Track";
    dataGridView1.Columns[1].DefaultCellStyle.Alignment = 
        DataGridViewContentAlignment.MiddleCenter;
    dataGridView1.Columns[2].Name = "Title";
    dataGridView1.Columns[3].Name = "Artist";
    dataGridView1.Columns[4].Name = "Album";

    // Make the font italic for row four.
    dataGridView1.Columns[4].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Italic);

    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    dataGridView1.MultiSelect = false;

    dataGridView1.BackgroundColor = Color.Honeydew;

    dataGridView1.Dock = DockStyle.Fill;

    dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);
    dataGridView1.CellParsing += new DataGridViewCellParsingEventHandler(dataGridView1_CellParsing);
    addNewRowButton.Click += new EventHandler(addNewRowButton_Click);
    deleteRowButton.Click += new EventHandler(deleteRowButton_Click);
    ledgerStyleButton.Click += new EventHandler(ledgerStyleButton_Click);
    dataGridView1.CellValidating += new DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating);

}

.NET Framework
Disponível desde 2.0
Retornar ao início
Mostrar: