Partilhar via


Como: Exibir dados em um controle DataGridView do Windows Forms

You can display data in a DataGridView control by dragging items from the Janela Fontes de Dados onto your form.Prior to dragging from the Data Sources window, set the control type of the table to DataGridView (this is the default setting for top-level items in the Data Sources window).Para obter mais informações, consulte Como: conjunto o controle to be Created when Dragging from the dados Sources janela. An alternative to displaying data in a grid is to display the data in individual controls.Para obter mais informações, consulte Como: Exibir dados em controles individuais Windows Forms.

Data can be displayed in a new DataGridView or in an existing one.When you drag items onto an existing grid, any previously established data bindings are replaced with the new items.

Displaying Data in a DataGridView Control

To display data in a new Windows Forms DataGridView control

  1. Abra a janela Data Sources.Para obter mais informações, consulte Como: em em aberto a janela de fonte de dados.

    Observação:

    Se a Fontes de dados janela vazia, em seguida, adicione uma fonte de dados a ele.Para obter mais informações, consulte Visão geral sobre fontes de dados.

  2. Abra o formulário no Windows Forms Designer.

  3. Select a table in the Data Sources window, click the drop-down arrow, and then select DataGridView.

  4. Drag the table from the Data Sources window to a form.

    Um controle DataGridView e uma faixa de ferramenta (BindingNavigator) para navegação em registros aparecem no formulário.Um DataSet,TableAdapter, BindingSource e BindingNavigator aparecem na bandeja de componentes.

To display data in an existing Windows Forms DataGridView control

  1. Abra a janela Data Sources.Para obter mais informações, consulte Como: em em aberto a janela de fonte de dados.

    Observação:

    Se a Fontes de dados janela vazia, em seguida, adicione uma fonte de dados a ele.Para obter mais informações, consulte Visão geral sobre fontes de dados.

  2. Abra o formulário no Windows Forms Designer.

  3. Select a table in the Data Sources window, click the drop-down arrow, and then select DataGridView.

  4. Drag the table from the Data Sources window onto a DataGridView on the form.

    The DataGridView control is now bound to the table that you have dragged onto it.A DataSet, TableAdapter, and BindingSource appear in the component tray.

Consulte também

Tarefas

Como: Exibir dados em controles individuais Windows Forms

Como: Adicionar controles personalizados à janela dados Sources

Como: Validar dados durante alterações de coluna

Conceitos

Exibindo visão geral de dados

Visão geral sobre fontes de dados

Referência

DataGridView Control Overview (Windows Forms)

Outros recursos

O Componente BindingSource

BindingNavigator Controlar (Windows Forms)