0

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..

5
Contributors
10
Replies
12
Views
8 Years
Discussion Span
Last Post by babbu
0

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.

0

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;
            .....
0

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;
0

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

0

Change the order of statements:

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

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.