Hide column and change size. Gridlookupedit

Asked

Viewed 51 times

0

I am using a Gridlookupedit, and I would like to hide the first column, and adjust the size of the others, however I am using gridLookUpEdit2View.Columns[0].Visible = false; and the gridLookUpEdit2.Properties.View.Columns[0].Visible = false; yet of error:

Additional information: The index was out of range. It should be non-negative and smaller than the collection size.

private void cmb_cli()
        {
            DataTable cli = new DataTable();

            string sqconn, _sql;

            sqconn = ConfigurationManager.ConnectionStrings["sql brayton max"].ConnectionString;

            _sql = @"SELECT id,cd_uf,ds_cidade FROM NotaFiscal.Cidades";

            SqlConnection con = new SqlConnection(sqconn);

        try
        {
            SqlCommand cmd = new SqlCommand(_sql, con);

            con.Open();

            cmd.CommandType = CommandType.Text;

            SqlDataAdapter da = new SqlDataAdapter(cmd);

            da.Fill(cli);
        }
        catch
        {

        }

            gridLookUpEdit2.Properties.DataSource = cli;
            gridLookUpEdit2.Properties.DisplayMember = "ds_cidade";
            gridLookUpEdit2.Properties.ValueMember = "id";


            gridLookUpEdit2View.Columns[0].Visible = false;    
            gridLookUpEdit2.Properties.View.Columns[0].Visible = false;



            gridLookUpEdit2.Properties.PopupFormWidth = 500;

        }

1 answer

0


Staff follows solution below, to modify the columns after popular

Remember to use namespace:

using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Columns;

private void Form1_Load(object sender, EventArgs e)
    {
        // Cria uma instancia de col2, e adiciona a minha coluna do datatable de nome UF
        GridColumn col2 = gridLookUpEdit2.Properties.View.Columns.AddField("UF");
        // definição da ordem de coluna, primeira coluna index 0.
        col2.VisibleIndex = 0;
        // nome da coluna
        col2.Caption = "UF";
        // defini o tamanho da coluna
        col2.Width = 350;

        GridColumn col3 = gridLookUpEdit2.Properties.View.Columns.AddField("ID");
        col3.VisibleIndex = 1;
        col3.Caption = "ID";
        col3.Visible = false;

        GridColumn col4 = gridLookUpEdit2.Properties.View.Columns.AddField("CIDADE");
        col4.VisibleIndex = 2;
        col4.Caption = "CIDADE";

        // defini o tamanho do popup ao clicar no controle.
        gridLookUpEdit2.Properties.PopupFormWidth = 500;
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.