how can you remove the excess width in may datagridview??? after that long blank space theres another field.. as shown in the image..


my code goes something like this

//create a command builder
                    OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);

                    //create a DataTable to hold the query results
                    DataTable dTable = new DataTable();

                    //fill the DataTable
                    dAdapter.Fill(dTable);
                    //the DataGridView


                    //BindingSource to sync DataTable and DataGridView
                    BindingSource bSource = new BindingSource();

                    //set the BindingSource DataSource
                    bSource.DataSource = dTable;

                    //set the DataGridView DataSource
                    dataGridView1.DataSource = bSource;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.AutoResizeColumns();
                    dataGridView1.AutoResizeRows();
                    dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

thanks

Recommended Answers

Is your data stored with trailing spaces (ie char(100) and not varchar(100) in the database)? Try to .Trim() the underlying data in the DataTable and resize it again. You should probably also set the WrapMode property before AutoResizing since it could change the control's layout.

Jump to Post

All 2 Replies

Is your data stored with trailing spaces (ie char(100) and not varchar(100) in the database)? Try to .Trim() the underlying data in the DataTable and resize it again. You should probably also set the WrapMode property before AutoResizing since it could change the control's layout.

Is your data stored with trailing spaces (ie char(100) and not varchar(100) in the database)? Try to .Trim() the underlying data in the DataTable and resize it again. You should probably also set the WrapMode property before AutoResizing since it could change the control's layout.

thanks for that helpful tips.. wrapmode and other datagrid properties did the trick..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.