I want to display the DB data in a table, but so far I have been able to do it with a ListView
. How can I do this but using a DataGridView
?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
using MongoDB.Driver.Linq;
namespace WFRecibos
{
public partial class frmListaClientes : Form
{
public frmListaClientes()
{
InitializeComponent();
}
public IEnumerable<Cliente> getTodosClientes()
{
var colClientes = DbHelper.getCollection("Cliente");
var clienteLista = from e in colClientes.AsQueryable<Cliente>() select e;
return clienteLista;
}
private void frmListaCli_Load(object sender, EventArgs e)
{
var consulta = this.getTodosClientes();
listView1.Items.Clear();
foreach (var cli in consulta)
{
listView1.Items.Add(cli.Nome);
listView1.Items.Add(cli.Municipio);
listView1.Items.Add(cli.Corrego);
}
}
private void gdvClientes_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}