Identifier in grid lines

0

Could you tell me if there is any simple property or way of putting an identifier in the rows of the grid but without being the ID in the table, for example I have 5 records with id 32,45,99,100ee 200. But I want to put on the grid 1,2,3,4 and 5. Type an auto increment, any suggestions?

Code used for the Grid:

    var lista = from substituidos in vagaDTO.Substituidos
                        where substituidos.Operacao != SysDTO.Operacoes.Exclusao
                        select new
                        {            

                            substituidos.IdClasse,
                            substituidos.Id,
                            Matrícula = substituidos.Matricula_Substituido ,
                            Substituído = substituidos.Substituido,
                            Contratante = substituidos.Numero_CTT,
                            Local = (substituidos.Endereco == null ? "" : substituidos.Endereco.Sigla),
                            Dt_Enc = string.Format("{0:dd/MM/yy}", substituidos.Data_Enc),
                            Dt_Saída = string.Format("{0:dd/MM/yy}", substituidos.Data_Saida),
                            Prev_Deslig = string.Format("{0:dd/MM/yy}", substituidos.Prev_Desligamento),
                            Prev_Fer_Ini = string.Format("{0:dd/MM/yy}", substituidos.Prev_Ferias_Inicio),
                            Prev_Fer_Fim = string.Format("{0:dd/MM/yy}", substituidos.Prev_Ferias_Final),
                            Fer_Ini = string.Format("{0:dd/MM/yy}", substituidos.Ferias_Inicio),
                            Fer_Fim = string.Format("{0:dd/MM/yy}", substituidos.Ferias_Final)

                        };

            //dtgSubstituidos.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            lista = lista.OrderBy(p => p.Substituído).ToList();
            dtgSubstituidos.DataSource = lista.ToList();



            dtgSubstituidos.Columns[0].Visible = false;
            dtgSubstituidos.Columns[1].Visible = false;
            dtgSubstituidos.Columns[4].Visible = false;

            dtgSubstituidos.Columns[2].Width = 50;
            dtgSubstituidos.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

            dtgSubstituidos.Columns[3].Width = 150;
            dtgSubstituidos.Columns[5].Width = 200;

            dtgSubstituidos.Columns[6].Width = 60;
            dtgSubstituidos.Columns[6].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            dtgSubstituidos.Columns[7].Width = 60;
            dtgSubstituidos.Columns[7].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            dtgSubstituidos.Columns[8].Width = 60;
            dtgSubstituidos.Columns[8].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            dtgSubstituidos.Columns[9].Width = 60;
            dtgSubstituidos.Columns[9].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            dtgSubstituidos.Columns[10].Width = 60;
            dtgSubstituidos.Columns[10].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            dtgSubstituidos.Columns[11].Width = 60;
            dtgSubstituidos.Columns[11].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            dtgSubstituidos.Columns[12].Width = 60;
            dtgSubstituidos.Columns[12].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;                            
    
asked by anonymous 22.08.2017 / 22:49

1 answer

0

declares a int out of the expression, and places a property with the value inside the expression, and increments:

 int i  = 0;
 var lista = from substituidos in vagaDTO.Substituidos
                    where substituidos.Operacao != SysDTO.Operacoes.Exclusao
                    select new
                    {            
                        Sequencia = i++;
                        substituidos.IdClasse,
                        substituidos.Id,
                        Matrícula = substituidos.Matricula_Substituido ,
                        Substituído = substituidos.Substituido,
                        Contratante = substituidos.Numero_CTT,
                        Local = (substituidos.Endereco == null ? "" : substituidos.Endereco.Sigla),
                        Dt_Enc = string.Format("{0:dd/MM/yy}", substituidos.Data_Enc),
                        Dt_Saída = string.Format("{0:dd/MM/yy}", substituidos.Data_Saida),
                        Prev_Deslig = string.Format("{0:dd/MM/yy}", substituidos.Prev_Desligamento),
                        Prev_Fer_Ini = string.Format("{0:dd/MM/yy}", substituidos.Prev_Ferias_Inicio),
                        Prev_Fer_Fim = string.Format("{0:dd/MM/yy}", substituidos.Prev_Ferias_Final),
                        Fer_Ini = string.Format("{0:dd/MM/yy}", substituidos.Ferias_Inicio),
                        Fer_Fim = string.Format("{0:dd/MM/yy}", substituidos.Ferias_Final)

                    };

With this, your Grid column 0 will be Sequencia .

Please note that your ordering must be done in LINQ as well, otherwise the numbering will not help.

source: link

    
22.08.2017 / 23:58