xxxxxxxxxx
dataGridView1.Rows.Clear();
dataGridView1.Refresh();
xxxxxxxxxx
// If "dataGridView1.Rows.Clear();" Not work Use the Following
do
{
foreach (DataGridViewRow row in dataGridViewError.Rows)
{
try
{
dataGridViewError.Rows.Remove(row);
}
catch (Exception) { }
}
} while (dat
xxxxxxxxxx
using System;
using System.Windows.Forms;
namespace DataGridViewCombo1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
dataGridView1.RowCount = 5;
for (int index = 0; index < dataGridView1.Rows.Count -1; index++)
{
dataGridView1.Rows[index].Cells[0].Value = index;
}
}
private void RemoveButton_Click(object sender, EventArgs e)
{
dataGridView1.AllowUserToAddRows = false;
try
{
while (dataGridView1.Rows.Count > 1)
{
dataGridView1.Rows.RemoveAt(dataGridView1.Rows.Count - 1);
}
}
finally
{
dataGridView1.AllowUserToAddRows = true;
}
}
}
}