views:

271

answers:

3

how to connect multiple tables and populate into a datagridview control ? What i can think is create a view, but if there any other better resolutions ?

A: 

A view is probably the best simple solution here.

Can you post a sample of your domain model so that we may be of better help?

One thing is for sure: "The simpler the better". Keep it simple! =)

Will Marcouiller
A: 

If you need to join output from several tables and show in the gridview than you need to create a view or stored proc returning necessary results and bind its data to the grid.

Andrew Bezzub
A: 

Instead of binding, I'd use virtual mode. That makes it pretty easy to pull data on-the-fly from different sources. Microsoft has a tutorial on how to use it: How to: Implement Virtual Mode in the Windows Forms DataGridView Control

Essentially, instead of loading all of the data at start up or using a binding source, you hook the CellValueNeeded event. The DataGridView will fire that event whenever it needs to display a cell and you can supply whatever data you want at that time. In your CellValueNeeded handler, you can map the row and column of the DataGridView to your tables however you would like.

private void my_init_function() {
    datagridview.VirtualMode = true;
    datagridview.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(datagridview_CellValueNeeded);
}

private void datagridview_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
{
    e.Value = get_my_data(e.RowIndex, e.ColumnIndex);
}
Daniel Stutzbach
what is virtual mode ?
MemoryLeak
@MemoryLeak: I updated my answer with additional explanation, a link to Microsoft's tutorial on virtual mode, and a very brief example. Let me know if you have further questions.
Daniel Stutzbach