una ultimo ultima seleccionar seleccionada registro posicionarse poner obtener net foco fila datos buscar asp c# winforms datagridview

ultimo - seleccionar ultima fila datagridview c#



Cómo encontrar una fila en datagridview y añádala a la última fila del datagridview (4)

Estoy teniendo una vista de cuadrícula que tendrá 2 filas con algunos datos de la siguiente manera

101 111111111 1111111111009270754A094101// My first row data 9000002 1000000020222222236000000000000000000000012000000000000000000000000000000000000000//My 2nd row data

Agregaré algunos valores para que se inserten entre estas 2 filas y esa segunda fila ya existente se mueva a la última fila de la vista de cuadrícula de datos. Al igual que si agrego n cantidad de valores, los valores deben insertarse entre esos 2 y esa fila que ya existía debe moverse a la última fila, cualquier idea, por favor


Esto fue lo que escribí, pero no funciona para mí. Lo que necesito es que si mi matriz comienza con 5, me gustaría eliminar la 2ª fila que ya existía en la vista de cuadrícula y me gustaría agregarla después de agregar la fila en particular.

if (line.StartsWith("5")) { int oldRow = 1; dataGridView1.Rows.Add(itemarray(dataGridView1.Rows[1])); dataGridView1.Rows.RemoveAt(oldRow); dataGridView1.Rows.Add("BatchHeader", line); m_flag = true; StringBuilder sb = new StringBuilder(); objfileentry.createFileEntry(Append.FileName, out sb); if (m_flag) dataGridView1.Rows.Add("FileControl", sb.ToString()); line = string.Empty; }

La función dada por ti

private object[] itemarray(DataGridViewRow Row) { int a = Row.DataGridView.ColumnCount - 1; object[] mOut = new object[a + 1]; for (int x = 0; x <= a; x++) { mOut[x] = Row.Cells[x].Value; } return mOut; }


He editado esto con un código probado:

public Form1() { InitializeComponent(); //This can be removed before utilizing dgv.Rows.Add("1", "1", "1"); dgv.Rows.Add("1", "1", "1"); dgv.Rows.Add("bob", "bob", "bob"); dgv.Rows.Add("1", "1", "1"); dgv.Rows.Add("1", "1", "1"); dgv.Rows.Add("1", "1", "1"); //This can be removed before utilizing int oldrow = 2; dgv.Rows.Add(itemArray(dgv.Rows[oldrow])); dgv.Rows.RemoveAt(oldrow); /* DataGridViewRow oldRow = dataGridView1.Rows.Add(itemarray(dataGridView1.Rows[1])); dataGridView1.Rows.Remove(oldRow) */ } object[] itemArray(DataGridViewRow Row) { int a = Row.DataGridView.ColumnCount - 1; object[] mOut = new object[a+1]; for (int x = 0;x <= a ; x++) { mOut[x] = Row.Cells[x].Value; } return mOut; }

Me disculpo por todas las pruebas adicionales.


¿Puedes usar ListView en lugar de datagrid?


Si está vinculando datos de esta manera,

myGridView.DataSource = GetDataSource();

No puede agregar filas programáticamente. Si no, puede usar:

DataGridViewRow newRow = new DataGridViewRow(); //set row data here myGridView.Rows.Insert(newIndex, newRow); //use Insert instead of Add/AddCopy