本人新手,剛接觸C#3個月
有這樣一段代碼
for (int i = 0; i < dataGridView1.Rows.Count-1;i++ )
{
dataGridView1.ClearSelection();
dataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable;
string sqlX = string.Empty;
sqlX += "SELECT enable FROM XITEM WHERE LEFT(HOKAN,2)='BS' and code='" + dataGridView1.Rows[i].Cells["專案編碼"].Value.ToString() + "'";
string sql = Program.SqlCommandExecuteScalarReturnString1(sqlX);
{
if (sql == "0")
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.LightGray;
}
}
}
當我在表單專案編碼處輸入正確的專案編碼時不報錯,當輸入比如180模糊查詢時報以下錯誤

插入禁止排序陳述句是因為datagridview界面一點擊排序,之前查詢時滿足條件的背景變為灰色的資料就不顯示灰色了,請問如何解決
uj5u.com熱心網友回復:
寫的很清楚,訪問越界了,Column[i],這里的i是多少,除錯看看uj5u.com熱心網友回復:
問題已經找到了。把禁止列排序加到行的回圈里去了,重新加了一句回圈陳述句for (int i = 0; i < dataGridView1.Columns.Count;i++ )
{
this.dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/267855.html
標籤:C#
