novknow
asked on
Display last row of DataGridView control fully
I display last row of DataGridView control with this code:
...
dataGridView1.CurrentCell = dataGridView1.Rows[dataGri dView1.Row s.Count - 1].Cells[0];
dataGridView1.Show();
dataGridView1.AutoResize.. .
dataGridView1.Focus();
1) The first time the dataGridView1 is shown, the current cell is at the first row.
2) From second call onwards, the last row is displayed but partially.
How can I display the last row fully with the first execution of the code?
...
dataGridView1.CurrentCell = dataGridView1.Rows[dataGri
dataGridView1.Show();
dataGridView1.AutoResize..
dataGridView1.Focus();
1) The first time the dataGridView1 is shown, the current cell is at the first row.
2) From second call onwards, the last row is displayed but partially.
How can I display the last row fully with the first execution of the code?
ASKER
The program generate a report in table form (shown using datagridview) each time a user select his choice from the various controls - treeview,comboboxes,checkb oxes,....
The report should display the last row (usually the total) of the datagridview each time it is shown.
1) Problem is, the last row is not shown when the datagridview is first display but when the user select another set of criteria and generate the report the second time, the last is shown correctly!
2) Now, when the last row is visible, it is only partially visible (only 80% of the row is able the bottom edge). It becomes fully visible only if the up arrow key is pressed once.
The report should display the last row (usually the total) of the datagridview each time it is shown.
1) Problem is, the last row is not shown when the datagridview is first display but when the user select another set of criteria and generate the report the second time, the last is shown correctly!
2) Now, when the last row is visible, it is only partially visible (only 80% of the row is able the bottom edge). It becomes fully visible only if the up arrow key is pressed once.
how u are filling the lower row can u post the code
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
// constructor
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.Hide();
// loading...
dataGridView1.CellFormatti ng -= dataGridView1_CellFormatti ng;
dataGridView1.CellFormatti ng += dataGridView1_CellFormatti ng;
dataGridView1.CellMouseDow n -= dataGridView1_CellMouseDow n;
dataGridView1.CellMouseDow n += dataGridView1_CellMouseDow n;
dataGridView1.MouseDown -= dataGridView1_MouseDown;
dataGridView1.MouseDown += dataGridView1_MouseDown;
dataGridView1.MouseUp -= dataGridView1_MouseUp;
dataGridView1.MouseUp += dataGridView1_MouseUp;
dataGridView1.SelectionCha nged -= dataGridView1_SelectionCha nged;
dataGridView1.SelectionCha nged += dataGridView1_SelectionCha nged;
// Fill DataGridView...
// SQL code
dataGridView1.Columns.Clea r();
dataGridView1.DataSource = null;
dataTable1.Clear();
SqlDataAdapter dataAdapter1 = new SqlDataAdapter(cmd);
try
{
dataAdapter1.Fill(dataTabl e1);
dataGridView1.DataSource = dataTable1; // fill new data all OEE Mode
}
catch (SystemException ex)
{
dataGridView1.Columns.Clea r();
dataGridView1.DataSource = null;
dataGridView1.Hide();
}
// Show DataGridView...
dataGridView1.ColumnHeader sBorderSty le = DataGridViewHeaderBorderSt yle.Raised ;
dataGridView1.CellBorderSt yle = DataGridViewCellBorderStyl e.Single;
dataGridView1.GridColor = SystemColors.ActiveBorder;
dataGridView1.RowHeadersVi sible = false;
dataGridView1.SelectionMod e = DataGridViewSelectionMode. CellSelect ;
dataGridView1.MultiSelect = true;
dataGridView1.BackgroundCo lor = Color.Honeydew;
dataGridView1.ColumnHeader sHeightSiz eMode = DataGridViewColumnHeadersH eightSizeM ode.AutoSi ze;
for (int x = 0; x < dataGridView1.ColumnCount; x++)
{
dataGridView1.Columns[x].S ortMode = reportSort[x];
dataGridView1.Columns[x].H eaderText = reportTitle[x];
dataGridView1.Columns[x].D efaultCell Style.Alig nment = reportAlign[x];
}
dataGridView1.CurrentCell = dataGridView1.Rows[dataGri dView1.Row s.Count - 1].Cells[0];
if (dataGridView1.RowCount == 0)
dataGridView1.Hide();
else
{
dataGridView1.Show();
dataGridView1.AutoResizeCo lumns(Data GridViewAu toSizeColu mnsMode.Al lCells);
dataGridView1.Focus();
}
--- The End
The Fill and Show function above were called repeatedly each time a new selection is set.
I suspect there is some other events occurred which I did not expect.
I will step through the code once I get back to work.
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.Hide();
// loading...
dataGridView1.CellFormatti
dataGridView1.CellFormatti
dataGridView1.CellMouseDow
dataGridView1.CellMouseDow
dataGridView1.MouseDown -= dataGridView1_MouseDown;
dataGridView1.MouseDown += dataGridView1_MouseDown;
dataGridView1.MouseUp -= dataGridView1_MouseUp;
dataGridView1.MouseUp += dataGridView1_MouseUp;
dataGridView1.SelectionCha
dataGridView1.SelectionCha
// Fill DataGridView...
// SQL code
dataGridView1.Columns.Clea
dataGridView1.DataSource = null;
dataTable1.Clear();
SqlDataAdapter dataAdapter1 = new SqlDataAdapter(cmd);
try
{
dataAdapter1.Fill(dataTabl
dataGridView1.DataSource = dataTable1; // fill new data all OEE Mode
}
catch (SystemException ex)
{
dataGridView1.Columns.Clea
dataGridView1.DataSource = null;
dataGridView1.Hide();
}
// Show DataGridView...
dataGridView1.ColumnHeader
dataGridView1.CellBorderSt
dataGridView1.GridColor = SystemColors.ActiveBorder;
dataGridView1.RowHeadersVi
dataGridView1.SelectionMod
dataGridView1.MultiSelect = true;
dataGridView1.BackgroundCo
dataGridView1.ColumnHeader
for (int x = 0; x < dataGridView1.ColumnCount;
{
dataGridView1.Columns[x].S
dataGridView1.Columns[x].H
dataGridView1.Columns[x].D
}
dataGridView1.CurrentCell = dataGridView1.Rows[dataGri
if (dataGridView1.RowCount == 0)
dataGridView1.Hide();
else
{
dataGridView1.Show();
dataGridView1.AutoResizeCo
dataGridView1.Focus();
}
--- The End
The Fill and Show function above were called repeatedly each time a new selection is set.
I suspect there is some other events occurred which I did not expect.
I will step through the code once I get back to work.
// constructor
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.Hide();
// loading...
dataGridView1.CellFormatti ng -= dataGridView1_CellFormatti ng;
dataGridView1.CellFormatti ng += dataGridView1_CellFormatti ng;
dataGridView1.CellMouseDow n -= dataGridView1_CellMouseDow n;
dataGridView1.CellMouseDow n += dataGridView1_CellMouseDow n;
dataGridView1.MouseDown -= dataGridView1_MouseDown;
dataGridView1.MouseDown += dataGridView1_MouseDown;
dataGridView1.MouseUp -= dataGridView1_MouseUp;
dataGridView1.MouseUp += dataGridView1_MouseUp;
dataGridView1.SelectionCha nged -= dataGridView1_SelectionCha nged;
dataGridView1.SelectionCha nged += dataGridView1_SelectionCha nged;
// Fill DataGridView...
// SQL code
dataGridView1.Columns.Clea r();
dataGridView1.DataSource = null;
dataTable1.Clear();
SqlDataAdapter dataAdapter1 = new SqlDataAdapter(cmd);
try
{
dataAdapter1.Fill(dataTabl e1);
dataGridView1.DataSource = dataTable1; // fill new data all OEE Mode
}
catch (SystemException ex)
{
dataGridView1.Columns.Clea r();
dataGridView1.DataSource = null;
dataGridView1.Hide();
}
// Show DataGridView...
dataGridView1.ColumnHeader sBorderSty le = DataGridViewHeaderBorderSt yle.Raised ;
dataGridView1.CellBorderSt yle = DataGridViewCellBorderStyl e.Single;
dataGridView1.GridColor = SystemColors.ActiveBorder;
dataGridView1.RowHeadersVi sible = false;
dataGridView1.SelectionMod e = DataGridViewSelectionMode. CellSelect ;
dataGridView1.MultiSelect = true;
dataGridView1.BackgroundCo lor = Color.Honeydew;
dataGridView1.ColumnHeader sHeightSiz eMode = DataGridViewColumnHeadersH eightSizeM ode.AutoSi ze;
for (int x = 0; x < dataGridView1.ColumnCount; x++)
{
dataGridView1.Columns[x].S ortMode = reportSort[x];
dataGridView1.Columns[x].H eaderText = reportTitle[x];
dataGridView1.Columns[x].D efaultCell Style.Alig nment = reportAlign[x];
}
if (dataGridView1.RowCount == 0)
dataGridView1.Hide();
else
{
dataGridView1.Show();
dataGridView1.CurrentCell = dataGridView1.Rows[dataGri dView1.Row s.Count - 1].Cells[0];
dataGridView1.AutoResizeCo lumns(Data GridViewAu toSizeColu mnsMode.Al lCells);
dataGridView1.Focus();
}
try this i moved < dataGridView1.CurrentCell = dataGridView1.Rows[dataGri dView1.Row s.Count - 1].Cells[0];
>
to after dataGridView1.Show();
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.Hide();
// loading...
dataGridView1.CellFormatti
dataGridView1.CellFormatti
dataGridView1.CellMouseDow
dataGridView1.CellMouseDow
dataGridView1.MouseDown -= dataGridView1_MouseDown;
dataGridView1.MouseDown += dataGridView1_MouseDown;
dataGridView1.MouseUp -= dataGridView1_MouseUp;
dataGridView1.MouseUp += dataGridView1_MouseUp;
dataGridView1.SelectionCha
dataGridView1.SelectionCha
// Fill DataGridView...
// SQL code
dataGridView1.Columns.Clea
dataGridView1.DataSource = null;
dataTable1.Clear();
SqlDataAdapter dataAdapter1 = new SqlDataAdapter(cmd);
try
{
dataAdapter1.Fill(dataTabl
dataGridView1.DataSource = dataTable1; // fill new data all OEE Mode
}
catch (SystemException ex)
{
dataGridView1.Columns.Clea
dataGridView1.DataSource = null;
dataGridView1.Hide();
}
// Show DataGridView...
dataGridView1.ColumnHeader
dataGridView1.CellBorderSt
dataGridView1.GridColor = SystemColors.ActiveBorder;
dataGridView1.RowHeadersVi
dataGridView1.SelectionMod
dataGridView1.MultiSelect = true;
dataGridView1.BackgroundCo
dataGridView1.ColumnHeader
for (int x = 0; x < dataGridView1.ColumnCount;
{
dataGridView1.Columns[x].S
dataGridView1.Columns[x].H
dataGridView1.Columns[x].D
}
if (dataGridView1.RowCount == 0)
dataGridView1.Hide();
else
{
dataGridView1.Show();
dataGridView1.CurrentCell = dataGridView1.Rows[dataGri
dataGridView1.AutoResizeCo
dataGridView1.Focus();
}
try this i moved < dataGridView1.CurrentCell = dataGridView1.Rows[dataGri
>
to after dataGridView1.Show();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi gauthampj, tolgaong,
Thanks.
On the second question:
The last row was shown but sometime it did not show "fully".
And if the user pressed the arrow keys, datagridview than adjusted the rows to show fully!
Is it because my datagridview is sitting inside a panel control with docking set to Dock.Fill?
Thanks.
On the second question:
The last row was shown but sometime it did not show "fully".
And if the user pressed the arrow keys, datagridview than adjusted the rows to show fully!
Is it because my datagridview is sitting inside a panel control with docking set to Dock.Fill?
ASKER
I have tried not setting the DockStyle.Fill, it still didn't work.
Any suggestion?
Any suggestion?
when u do
dataGridView1.CurrentCell = dataGridView1.Rows[dataGri dView1.Row s.Count - 1].Cells[0];
the focus should come to the last row
dataGridView1.CurrentCell = dataGridView1.Rows[dataGri
the focus should come to the last row
<
1) The first time the dataGridView1 is shown, the current cell is at the first row.
2) From second call onwards, the last row is displayed but partially
>