在我的VS2015 Winform
應用程序中,有一個DataGridView
控件綁定到綁定到SQL數據庫的BindingSource
。網格有四列:ID,URL,名稱,類型。 URL列是DataGridViewLinkColumn
,其ReadOnly
屬性默認設置爲False
。我可以編輯名稱和類型列,但URL列顯示爲ReadOnly。爲什麼?我如何讓URL列可編輯?Winform DataGridViewLinkColumn ReadOnly屬性不起作用
0
A
回答
0
由於雷扎說:
DataGridViewLinkColumn
不可編輯。
因此,要在這樣的列中編輯單元格,必須根據需要將其轉換爲DataGridViewTextBoxCell
。舉例來說,如果我已經訂閱了DataGridView.CellContentClick
處理點擊一個鏈接,那麼我會處理CellDoubleClick
的電池轉換:
private void DataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (this.dataGridView1.Columns[e.ColumnIndex] == this.dataGridView1.Columns["URL"])
{
this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] = new DataGridViewTextBoxCell();
this.dataGridView1.BeginEdit(true);
}
}
一旦你進入你的價值,並離開該小區,則應使用CellValidated
驗證新值是一個URI的單元轉換回一個DataGridViewLinkCell
之前:
private void DataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
{
if (this.dataGridView1.Columns[e.ColumnIndex] == this.dataGridView1.Columns["URL"])
{
DataGridViewCell cell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (Uri.IsWellFormedUriString(cell.EditedFormattedValue.ToString(), UriKind.Absolute))
{
cell = new DataGridViewLinkCell();
}
}
}
買者:
這只是工作的我,當爲「URL」列中的數據是字符串,因此結合後,列默認爲一個
DataGridViewTextBoxColumn
- 迫使手動轉換鏈接細胞開始:private void DataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { foreach (DataGridViewRow r in dataGridView1.Rows) { if (Uri.IsWellFormedUriString(r.Cells["URL"].Value.ToString(), UriKind.Absolute)) { r.Cells["URL"] = new DataGridViewLinkCell(); } } }
從一開始就將「URI」列設置爲
DataGridViewLinkColumn
,允許將單元格成功轉換爲TextBox
類型。但是,當轉換回鏈接單元時,調試顯示轉換髮生,但單元格格式和行爲失敗。
相關問題
- 1. meteor/react - 「readOnly」屬性有什麼作用?
- 2. c#Textbox ReadOnly屬性有時可以工作,有時不起作用
- 3. List和ReadOnly屬性
- 4. 如何更改winform中文本框的readonly屬性false?
- 5. decelerationRate屬性不起作用
- 6. ExpectedException屬性不起作用
- 7. Container.ItemIndex不起作用屬性
- 8. CompilationRelaxations屬性不起作用
- 9. c#屬性不起作用?
- 10. Jqgrid:viewGridRow屬性不起作用
- 11. CollectionViewSource:LiveShaping屬性不起作用
- 12. MvcSiteMapProvider屬性不起作用
- 13. InternalsVisibleTo屬性不起作用
- 14. 屬性不起作用
- 15. tplWriteMode屬性不起作用
- 16. DataType屬性不起作用
- 17. android:largeHeap屬性不起作用?
- 18. DebuggerDisplay屬性不起作用
- 19. onsubmit屬性不起作用
- 20. UIImageView.hidden屬性不起作用?
- 21. wpf附屬屬性不起作用
- 22. ReadOnly屬性與IF語句
- 23. UWP中的ReadOnly屬性
- 24. RIA服務/ DataForm:如何一起使用ReadOnly和描述屬性
- 25. 分配給'readonly'屬性的屬性不允許
- 26. 不能在datagridviewlinkcolumn
- 27. 使用public readonly屬性釋放iVar
- 28. WPF ReadOnly使用MVVM的依賴屬性
- 29. 按鈕屬性「禁用」不起作用
- 30. 禁用的屬性不起作用
'DataGridViewLinkColumn'不可編輯。它僅將內容顯示爲鏈接。 –
數據實際上是在數據庫中更改(readwrite)還是僅在表單上(可能仍是隻讀的,只是「戲弄」你)? –