使DataGridView中的一列只读

时间:2013-12-09 10:18:00

标签: vb.net datagridview

在我的程序中,我已经包含了一个在表单加载时填充的datagridview。首次加载时,我将整个表单设置为只读。但是,如果用户想要编辑其中的数据,他们可以单击我在表单上包含的编辑按钮,其中包含以下代码:

datagrdSnippets.AllowUserToDeleteRows = True 'Allows user to delete rows
datagrdSnippets.ReadOnly = False 'Allows user to edit cells within the data grid

但是我不希望datagridview中的某个列可以编辑,我可以使用哪些代码来执行此操作?

4 个答案:

答案 0 :(得分:3)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Column1.ReadOnly = True
        Column2.ReadOnly = True
        Column3.ReadOnly = True
End Sub

在表单加载事件

上设置readonly true您想要的列

答案 1 :(得分:0)

@MessageDriven(name = "VerySimpleMDB", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "/jms/topic/targetTopic"),
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "useJNDI",propertyValue = "true"),
        @ActivationConfigProperty(propertyName = "clientID", propertyValue = "quickuser"),
        @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
        @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "topicBridge"),
        @ActivationConfigProperty(propertyName = "shareSubscriptions", propertyValue="true"),
        @ActivationConfigProperty(propertyName = "hA", propertyValue = "true")
},mappedName = "java:jboss/jms/topic/targetTopic")

public class VerySimpleMDB implements MessageListener {

答案 2 :(得分:0)

 dataGrid.Columns(index).ReadOnly = True
 dataGrid.Columns(index).ReadOnly = True

 dataGrid.Columns("column_name").ReadOnly = True

答案 3 :(得分:0)

我,我的 val obs = userModel.responseAPI.observe(this, Observer { if (it != null) { if(it.httpCode == 200) Log.e(TAG, "Response: " + it.toString()) else{ Log.e(TAG, "Response: " + it.toString()) } } }) 中有来自数据库的数据源,因此我使用for循环来获取要创建的确切列地址 class UserViewModel: ViewModel() { private val cd = CompositeDisposable() val status: MutableLiveData<Boolean>? = MutableLiveData<Boolean>() val responseAPI = MutableLiveData<ResponseAdd>() fun hitAPi(userID: String, items: ArrayList<Item>){ val myModel = ModelAdd("",items,"in",userID,"" ) cd.add( RetrofitHelper.apiInstance.addToCart(myModel) .myApiSubscriber(status) .subscribe({ responseAPI.postValue(it) },{ it.printStackTrace() }) ) } private fun <T> Single<T>.myApiSubscriber(status: MutableLiveData<Boolean>?): Single<T> { return this.doOnSubscribe { status?.postValue(true) Utils.debugger("PROGRESS ", " doOnSubscribe") }.doFinally { status?.postValue(false) Utils.debugger("PROGRESS ", " doFinally") }.subscribeOn(Schedulers.io()) } override fun onCleared() { cd.dispose() super.onCleared() } } ,其余的是dataGridView

代码:

ReadOnly=true