m using ms access and c#
i fetch the data frm the database which includes sr.no. and store in a data table.
i thn display the contents using a datagridview.
everythin is working fine..
heres the catch
i do not want to display the sr.no...how can i make tht particular column invisible.
although i do not display the sr.no. i still require it during runtime..

There is a Column.Visible property, you should be able to set that to false. How you do that depends on how you are binding the data to the grid view.

Turn off AutoGenerateColumns property.

Take a look,

......
            dataGridView1.AutoGenerateColumns = false;
            DataGridViewTextBoxColumn c1 = new DataGridViewTextBoxColumn();
            DataGridViewTextBoxColumn c2= new DataGridViewTextBoxColumn();
            c1.HeaderText = "HeaderText_for_field1";
            c2.HeaderText = "HeaderText_for_field2";
               
            c1.DataPropertyName = "field1";
            c2.DataPropertyName = "field2";

            dataGridView1.Columns.Add(c1);
            dataGridView1.Columns.Add(c2);

            dataGridView1.DataSource = your_data_source;
            .....

Adding to what private void said there is also a mapping type porperty on data tables. Setting it to mappingtype.hidden will do the same.

DataGridView dgv = new DataGridView();
            dgv.Columns["ColumnName"].Visible = false;

            DataTable dt = new DataTable();
            dt.Columns["ColumnName"].ColumnMapping =   MappingType.Hidden;

i tried it the adatapost's way

dataGridView1.DataSource = null;

            OleDbDataAdapter clientinfoDataAdapter;
            DataTable clientinfoDataTable = new DataTable();
            OleDbCommandBuilder clientinfoCommandBuilder;

            clientinfoDataAdapter = new OleDbDataAdapter("Select * from customer", Module1.oledbcon);
            clientinfoDataAdapter.Fill(clientinfoDataTable);
            clientinfoCommandBuilder = new OleDbCommandBuilder(clientinfoDataAdapter);

            dataGridView1.DataSource = clientinfoDataTable;

but in the datagridview i can see only blank textboxes

Change the order of statements:

clientinfoCommandBuilder = new OleDbCommandBuilder(clientinfoDataAdapter);
clientinfoDataAdapter.Fill(clientinfoDataTable);

ok got the error now its working.
now i also want to add a check box column in the datagridview.
however i want it to be the column in the extreme right.
i can simply create a new check box column. but whn i assign a datasource to the datagridview, the checkbox column becomes the column on the extreme left.

ne suggestions?

This question has already been answered. Start a new discussion instead.