Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Datagrid C# question.
 

Datagrid C# question.

Hi there,

I decided to start off learning C# by doing come datagrid stuff.

My problem is that I don't know how to select a few columns from a full table when I am trying to display all the data on a datagrid.

The code I am running is here:

namespace ECN

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

// TODO: This line of code loads data into the 'eCNFormsDataSet.ECN_Main' table. You can move, or remove it, as needed.

this.eCN_MainTableAdapter.Fill(this.eCNFormsDataSet.ECN_Main);

this.MaximizeBox = false;

}

private void button1_Click(object sender, EventArgs e)

{

this.eCN_MainTableAdapter.ClearBeforeFill = true;

this.eCN_MainTableAdapter.Fill("Want to fill this with specific Columns.");

}

}

}

Can anyone give me some suggestions? I already tried to look online, but the solutions are too complex for what I think should be a really simple problem. Thanks in advance!

Ke

Ke Sun  Thursday, October 12, 2006 6:55 PM
If you are trying to limit the data returned from the database, change the SQL select statement that is used by the table adapter. If you are trying to limit thefields from the datasource that are displayed in the DataGridView, set the AutoGenerateColumns property to false, and then explicitly create the columns for the fields you want to display.
CommonGenius.com  Friday, October 13, 2006 12:19 AM

to programmatically select columns, have you tried this?

this.theDataGridView.Columns[index].Selected = true;

this will select a column at the specified index. Is this what you are after?

ahmedilyas  Thursday, October 12, 2006 7:05 PM
If you are trying to limit the data returned from the database, change the SQL select statement that is used by the table adapter. If you are trying to limit thefields from the datasource that are displayed in the DataGridView, set the AutoGenerateColumns property to false, and then explicitly create the columns for the fields you want to display.
CommonGenius.com  Friday, October 13, 2006 12:19 AM

Thanks for the reply! ^_^

I think this will be very helpful, but what I had in mind was for the datagrid to display the columns or rows I want by using C# commands, and not using SQL. Is this possible?

Thanks,

Ke

Ke Sun  Friday, October 13, 2006 8:04 PM

to display the columns and rows of data? Well you can, just bind the datagrid to the datasource (dataset)

this.theDataGrid.DataSource = theDataSet.Tables[index].DefaultView;

is this what you are after? It will display all the records in the dataset/datatable into the datagrid

ahmedilyas  Friday, October 13, 2006 8:46 PM

Ke.S wrote:

...what I had in mind was for the datagrid to display the columns or rows I want by using C# commands, and not using SQL.

That's why I said:

CommonGenius.com wrote:

If you are trying to limit thefields from the datasource that are displayed in the DataGridView, set the AutoGenerateColumns property to false, and then explicitly create the columns for the fields you want to display.

CommonGenius.com  Friday, October 13, 2006 9:06 PM

You can use google to search for other answers

Custom Search

More Threads

• Custom DatagridTextBoxColumn having Bold font
• Recursive database access problem
• Remove the X from a from
• Navigating Master-Detail record
• Enter event not working on DataGrid?
• Handel DataGridView DataError event
• DataGridView - Checkboxes
• Datagrid message problem...
• How to draw the icon in RowHeaderCell of DataGridView in C#?
• Dataset