Windows Forms Datagridview (Select part of text in cell with mousepointer but dont allow edit) VB.NET

若如初见. 提交于 2019-12-11 15:11:50

问题


Hey guys i have a gridview on my form with readonly = false and enabled = true so i can select a part of the text in a cell of a datagridview. This works ok but when i have the settings like this its also possible to edit the text and thats the part i dont whant.

So i am looking for a solution to be able to select a part of the text within a cell of a datagridview but dont allow the users to edit the values that are in there.

Tanx in Advantage


回答1:


dataGridView1.ReadOnly = false and dataGridView1.enabled = true

Private Sub dataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs)
 If TypeOf e.Control Is TextBox Then
' Set the TextBoxCell to readonly
Dim textBoxCell As TextBox = DirectCast(e.Control, TextBox)
textBoxCell.[ReadOnly] = True
 End If
End Sub


来源:https://stackoverflow.com/questions/12971057/windows-forms-datagridview-select-part-of-text-in-cell-with-mousepointer-but-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!