0

I have this method using webservice to connect my desktop app to a oracle database:

public List<Persona> ListaPersona()
    {
        List<Persona> personas = new List<Persona>();
        Persona persona;
        Conexion con = new Conexion();
        OracleCommand cmd = con.OracleConexion().CreateCommand();
        cmd.CommandText = "select * from persona";
        DataSet ds = new DataSet();
        OracleDataAdapter adapter = new OracleDataAdapter(cmd);
        adapter.Fill(ds);
        foreach (DataRow fila in ds.Tables[0].Rows)
        {
            persona = new Persona();
            persona.IdPersona = Int32.Parse(fila["IDPERSONA"].ToString());
            persona.Rut = Int32.Parse(fila["RUT"].ToString());
            persona.DigiVeri = fila["DIGIVERI"].ToString();
            persona.Nombre = fila["NOMBRES"].ToString();
            persona.ApPaterno = fila["APPATERNO"].ToString();
            persona.ApMaterno = fila["APMATERNO"].ToString();
            persona.Edad = Int32.Parse(fila["EDAD"].ToString());
            persona.FechaNacimiento = fila["FECHA_NACIMIENTO"].ToString();
            persona.Genero = fila["GENERO"].ToString();
            persona.Correo = fila["CORREO"].ToString();
            persona.Telefono = Int32.Parse(fila["TELEFONO"].ToString());
            persona.Direccion = fila["DIRECCION"].ToString();
            persona.Comuna = Int32.Parse(fila["COMUNA"].ToString());
            persona.Contrasena = fila["CONTRASENA"].ToString();
            persona.Empresa = Int32.Parse(fila["EMPRESA"].ToString());
            persona.Cargo = Int32.Parse(fila["CARGO"].ToString());
            persona.Activo = Int32.Parse(fila["ACTIVO"].ToString());
            persona.Expositor = Int32.Parse(fila["EXPOSITOR"].ToString());
            persona.Personal = Int32.Parse(fila["PERSONAL"].ToString());
            persona.FechaIngreso = fila["FECHA_INGRESO"].ToString();
            personas.Add(persona);
        }
        return personas;
    }

It returns the list of all the users registered on the system, and i show them on a gridview. It display the data perfect, but in some random order i don't know why, so i wan't to reorder the colums of the gridview.

This is the windowsform load code:

public testLista()
    {
        InitializeComponent();
        WebService.ServicioClient s = new WebService.ServicioClient();
        dataGridView1.DataSource = s.ListaPersona().ToList();

    }
NEURO
  • 7
  • 4
  • i've tried the dataGridView.Columns["ColumnName"].DisplayIndex = 1; with all the columns but it work with some of them. – NEURO Oct 12 '17 at 02:12
  • What do you mean by record column? –  Oct 12 '17 at 05:39
  • what do you mean with "record"?. I didn't say that i belive. if u meant "reorder" i mean change the columns order. – NEURO Oct 12 '17 at 05:43
  • did you try https://stackoverflow.com/questions/3757997/how-to-change-datatable-columns-order –  Oct 12 '17 at 05:45
  • the dataset doesn't have the SetOrdinal method – NEURO Oct 12 '17 at 05:46
  • i guess the "DisplayIndex" it's the equivalent but i don't know why only worked with a couple of columns. – NEURO Oct 12 '17 at 05:48

1 Answers1

0

You can map it manually. On your DataGridView, you will see a triangle to the top right bottom. There you can map it manually according to the order you like. (Sorry, I coouldn't comment since I need 50 reputation, I only have 11)

NoobProgger
  • 70
  • 1
  • 9
  • Do you know if there's a way of re order the dataset?. I mean, the dataset sort automatically by vocabulary, that's why im getting the data in the way that i dont wan't to – NEURO Oct 12 '17 at 05:00
  • actually, it's weird. i am using almost the same pattern as yours (get the DataTable, then foreach every rows and map each to the properties of your list of items) and I always get the same exact arrangement of columns as the class (in your case, Persona) so I don't know how to arrange it but to manually map it to the datagridview on your form – NoobProgger Oct 12 '17 at 05:18