Save data from a Row to an array

3

I am designing a new feature for a Winforms project in C # . Soon I developed the following method that returns whether in the GridControl (gvDados) component there is a selected row or not.

public bool RetornaSelecionado(bool Selecionado)
{
  int linhas = 0;

  foreach (int i in gvDados.GetSelectedRows())
  {
    DataRow row = gvDados.GetDataRow(i);       
    linhas++;
     //TESTE MessageBox.Show(row[0].ToString());
  }
  if(linhas > 0)
  {
    MessageBox.Show("Selecionou");
    return Selecionado = true;
  }
  else
  {
    MessageBox.Show("Não selecionou");
    return Selecionado = false;
  }
}

The method worked the way I expected it to. When you select an item in the component, the Selected message is displayed, and when not selected, the message Not Selected is displayed. After this came up a question, how should I proceed to store the data from row to another array so that I can use it in another system validation?

    
asked by anonymous 25.09.2018 / 19:01

2 answers

0

Just create a lits<t> a where T is the class or type you want to store

Suppose it is an int

Lits<int> meusDados =  new List<int>();

foreach (int i in gvDados.GetSelectedRows())
{
    DataRow row = gvDados.GetDataRow(i);       
    linhas++;
    meusDados.Add(Int32.Parse(row[0].ToString()));
    //TESTE MessageBox.Show(row[0].ToString());
}
    
25.09.2018 / 20:36
0

Create an array of the type you are using in the datasource. To get the guy, just give him a cast.

MeuObjeto oObjeto = (MeuObjeto)gvDados.GetRow(i);

Then fill the array with these objects.

    
25.09.2018 / 20:31