कॉलम हेडर को छोड़कर मैं सभी डेटाग्रिडव्यू पंक्तियों को कैसे हटा सकता हूं?फॉर्म लोड पर सभी DataGridView पंक्तियों को कैसे निकालें?
मैंने कोशिश की:
dataGridView1.Rows.clear();
लेकिन यह काम नहीं करता।
मैं पंक्तियों पर पाश की कोशिश की और RemoveAt
विधि का उपयोग करें, लेकिन यह सभी पंक्तियों को दूर नहीं करता:
private void Form5_Load(object sender, EventArgs e)
{
dataGridView1.AutoGenerateColumns = true;
SqlConnection con = new SqlConnection(@"Data Source=.\myserver;Initial Catalog=test;Integrated Security=True");
adapter = new SqlDataAdapter("SELECT id as [#], description as [Description], unit as [Unit], amount as [Amount], unitPrice as [Unit Price], total as [Total] FROM tbl_poMaterials", con);
adapter.SelectCommand.CommandType = CommandType.Text;
DataTable tb = new DataTable();
adapter.Fill(tb);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
dataGridView1.DataSource = tb;
dataGridView1.Columns[0].Width = 30;
dataGridView1.Columns[0].ReadOnly = true;
dataGridView1.Columns[1].Width = 660;
for (int i = 0; i < tb.Rows.Count; i++)
{
tb.Rows.RemoveAt(i);
}
}
परिभाषित करें "लेकिन यह काम नहीं करता है", क्या होता है? –
[DataGridView.Clear()] के संभावित डुप्लिकेट (http://stackoverflow.com/questions/3744882/datagridview-clear) –