我需要知道是否可以禁用DataGrid中的特定單元格編輯,而不是禁用了Silverlight 4中整個列的編輯。我可以將特定單元格對象作爲FrameworkElement獲取,但它不包含屬性IsReadOnly或IsEnabled。 您可能會問:爲什麼我需要這個?那麼我的應用程序需要根據其他單元格內容禁用行中的特定單元格。每行都是以這種方式單獨檢查。 如果你有一個想法,我怎麼能達到這樣一個不尋常的行爲,請寫;)禁用DataGrid中的特定單元格編輯
2
A
回答
1
如果你有行,單元格的列索引/您希望禁用了細胞:
int r = 2, c = 4;
然後你可以聽的事件CellEnter和CellLeave並執行以下操作:
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == r)
{
if (e.ColumnIndex == c)
{
dataGridView1.Columns[e.ColumnIndex].ReadOnly = true;
}
}
}
private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == r)
{
if (e.ColumnIndex == c)
{
dataGridView1.Columns[e.ColumnIndex].ReadOnly = false;
}
}
}
你還是設置爲只讀整列,但因爲你是重置回你離開它出現的效應細胞後,只爲細胞工作。
0
感謝NominSim,這可以幫助我我解決proplem太多,但作爲neurotix 沒有找到CellEnter和CellLeave方法在我的DataGrid中在Silverlight 4
正如NominSim說,你需要知道的行索引和列。
我如何解決這個問題:
禁用編輯
System.Windows.Threading.DispatcherTimer timMakeEditable = new System.Windows.Threading.DispatcherTimer();
private void dataGrid1_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
{
timMakeEditable.Interval = new TimeSpan(0, 0, 0, 0, 100); // 100 Milliseconds
timMakeEditable.Tick += new EventHandler(timer_Tick);
timMakeEditable.Start();
if (e.RowIndex == r && e.ColumnIndex == c)
{
dataGrid1.Columns[yourColumnIndex].IsReadOnly = true;
}
}
啓用編輯
幾毫秒後,定時器使能列:
void timer_Tick(object sender, EventArgs e)
{
dataGrid1.Columns[yourColumnIndex].IsReadOnly = false;
timMakeEditable.Stop();
}
我認爲使用cellEditEnded是一個更好的主意,但它並不適合我。
0
您可以使用特定的細胞IsReadOnly屬性這樣
<DataGridTextColumn Header="ID"
Binding="{Binding ID}"
IsReadOnly="True"/>
我這個這是禁用特定細胞最好的主意。 謝謝
相關問題
- 1. 無法編輯DataGrid中的特定單元格WPF
- 2. 禁用Slick grid中的特定單元格編輯
- 3. 如何禁用編輯WPF Datagrid中的單元格?
- 4. 在DataGrid中編輯單元格(WPF)
- 5. Silverlight datagrid禁用特定單元
- 6. WPF datagrid - 編輯的單元格的值
- 7. WPF禁用DataGrid單元格
- 8. 如何編輯綁定DataGrid中的未綁定單元格?
- 9. PrimeNG Datatable - 禁止特定行的單元格編輯
- 10. 禁用TableView中的特定單元格
- 11. 禁用datagrid中的單元格
- 12. DataGrid在單元格編輯後刷新
- 13. WPF Datagrid更新單元格編輯
- 14. C#wpf mvvm datagrid編輯單元格
- 15. C#datagrid編輯單元格MVVM
- 16. DataGrid單元格編輯事件
- 17. WPF Datagrid單元格值編輯C#
- 18. PropertyGrid UITypeEditor禁用單元格編輯
- 19. extjs禁用單元格編輯
- 20. 如何禁用extjs編輯器網格內的特定單元格
- 21. 如何在特定的單元格ios中禁用編輯模式? ( - )
- 22. 禁用單元格編輯或使單元格只讀
- 23. WPF C#DataGrid編輯單元
- 24. 禁用NSTableView上的特定單元格
- 25. DataGrid禁用數據編輯
- 26. 以編程方式編輯wpf中的datagrid單元格
- 27. 在ExtJs 3.4網格的特定單元格中開始編輯
- 28. 如何在使用行編輯器進行編輯時禁用extjs 4.1.1中某行的特定單元格?
- 29. wpf datagrid:使單元格可編輯和不可編輯
- 30. wx.ListCtrl與TextEditMixin - 禁用編輯選定的單元格
我用了一點不同的方法。我迷上了DataGrid的CurrentCellChanged事件和CellEditEnded事件。但這個想法真的很有幫助。謝謝! – neurotix 2012-02-13 13:48:06
小心與我們分享您是如何實施這個的?謝謝。 – tobewan 2012-08-22 21:17:56
你不知道什麼**布爾邏輯**是,是嗎? – Arnthor 2012-12-06 12:19:26