人が「検索」をクリックしたときに検索基準に基づいて顧客を満たすデータグリッドビューをC#に用意しました。私が抱えている問題は、ユーザーが検索ボタンを2回以上クリックして顧客を検索した場合、またはユーザーが別の検索を実行したい場合、最後の検索のすべての詳細がまだデータグリッドビューにあることです。今の大きな問題は、列が削除されていないか、追加が追加されているのではなく、複数回検索された後に、datagridview内のボタンの列インデックスが「0」になることです。DataGridViewを空にする
ここで問題を把握したので、今後誰かが細部を見てみたいと思っている場合に備えて、ここで詳しく説明します。この問題は、custDataGridView.DataSource = nullを削除したときのようでした。いくつかのあいまいさがあるように見えたとして一部、すべてが
を動作するように見え、ここでコードがいっぱいである:あなたの忍耐のため
DataGridViewButtonColumn custAddJobSelect = new DataGridViewButtonColumn();
Datatable dt = new Datatable();
// ---> This was the culprit ---> custDataGridView.DataSource = null;
dt.Rows.Clear();
#region SQL connection String
...//CustQuery is the SQL stuff, conn is connection to DB.
#endregion
da = new System.Data.SqlClient.SqlDataAdapter(CustQuery, conn);
da.Fill(dt);
conn.Close();
custDataGridView.DataSource = dt;
if (AddJobGone == false)
{
AddJobGone = true;
custAddJobSelect.DisplayIndex = 0;
custDataGridView.Columns.Add(custAddJobSelect);
}
private void custDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == this.custDataGridView.Columns.Count - 1)
{
string addJobsCustNo = custDataGridView.Rows[e.RowIndex].Cells[0].FormattedValue.ToString();
txtAddJobsCustNo.Text = addJobsCustNo;
pnlAddJobSearchCustomer.Visible = false;
}
}
おかげで、これは他の誰かに役立ちます願っています!