Search code examples
sqlsql-serverdelphi-xedbgrid

DBgrid column very wide


We have the following case. We need to change a field in a SQL Server database from varchar to nvarchar. After the change, all the dbgrid shows the very wide column. How can we globally adjust the size of this column?

Column Lastname is very wide:


Solution

  • Let's create a sample table:

    CREATE TABLE PATIENT(
    ID INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
    LastName NVARCHAR(50) NOT NULL
    )
    GO
    INSERT INTO PATIENT VALUES
    ('Patient1'),
    ('Patient2'),
    ('Patient3');
    

    Now let's see the DBGrid how to show the data:

    enter image description here

    Your problem is the Sise of your column (50) here

    enter image description here

    You can change the DBGrid column Width as:

    DBGrid1.Columns[1].Width := Value;
    

    also, be sure that dgColumnResize option of the DBGrid is enabled (true), in that way you resize the column as needed at runtime.