I need to be able to accommodate the height of FORM
or DataGridView
based on the amount of data / rows that were filled in DataGrid
.
This taking into account what cases there are four rows, and others that there are only two rows or three, where there is a blank space that does not occupy the rows of DataGridView
.
Example 1 : In this example, the query returns four rows, and the space is almost complete:
Example 2 : In this example, the query returns only three rows and the space is much larger:
The idea is that, no matter if the query returns "n" row numbers , the space is the exact so that all rows are visible instantly , then, there is no need to use ScrollBar
How could I achieve this?
EDIT:
SOLUTION
Thank you in advance to those who participated and helped me: D
The code is shared:
Code in C#
/// <summary>
/// Función que se encarga de redimencionar el alto del formulario deacuerdo a la cantidad de datos que posee el datagrid view
/// </summary>
private void RedimencionarForm()
{
int AltoGridIni = Grid_Datos.Height;
int AltoGrid = 0;
int AltoForm = this.Height;
int Diferencia = 0;
AltoGrid = AltoGrid + Grid_Datos.ColumnHeadersHeight;
for (int i = 0; i <= Grid_Datos.Rows.Count - 1; i++)
{
AltoGrid = AltoGrid + Grid_Datos.Rows[i].Height;
}
Diferencia = AltoGridIni - AltoGrid;
if (Diferencia > 0)
{
AltoForm = AltoForm - Diferencia;
this.Height = AltoForm;
}
else if (Diferencia < 0)
{
AltoForm = AltoForm + Diferencia;
this.Height = AltoForm;
}
Grid_Datos.Height = AltoGrid;
}