Hide column and change size. GridLookUpEdit

0

I'm using a GridLookUpEdit, and I'd like to hide the first column, and adjust the size of the others, however I'm using gridLookUpEdit2View.Columns[0].Visible = false; and gridLookUpEdit2.Properties.View.Columns[0].Visible = false;

  

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

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;

        }
    
asked by anonymous 27.07.2016 / 17:17

1 answer

0

Personal follow 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;
    }
    
27.07.2016 / 21:22