什么甚至可以用来访问datagridview组合框的项目 [英] What even to be used to access the items of datagridview combo box

查看:48
本文介绍了什么甚至可以用来访问datagridview组合框的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个带组合框的datagridview. veen添加了一些物品. (例如说家具,物业等)

我希望当我选择属性,我的当前行应该得到文本属性的第2列.

为此甚至被解雇.我尝试了_CellValueChanged等,但是它们不起作用.

谢谢
Furqan

Hi,
I have a datagridview with a combobox coloumn. A few items have veen added to it. (Say Furniture, Property etc.)

I wish when I select Property, the column 2 of my current row should get text Property.

Which even to be fired for this. I tried _CellValueChanged etc. but they did not work.

Thanks
Furqan

推荐答案

很遗憾,没有任何活动.
以下是一些变通方法事件:
1. CellEndEdit事件:
但是它只有在离开牢房时才会被触发
2. CurrentCellDirtyStateChanged事件:
更改时立即触发,但仅在第一个更改时触发.如果您留在牢房中&继续更改checkstate,则第一次更改后您将不会再收到该事件.离开单元格后,事件将再次触发.
3.使用CellContentClick事件:这是最合适的.更改checkstate时触发.

请注意,所有这些事件都会针对所有类型的列&不只是复选框列.因此,一旦发生事件,您应该检查列类型&然后检查状态.
Unfortunately there are no events for that.
Here are a few workaround events:
1. CellEndEdit Event:
But its only fired when leaving the cell
2. CurrentCellDirtyStateChanged event:
Immediately fires upon change, but only for the first change. if you stay in the cell & keep changing checkstate, you will not receive the event after the first change. Event is once more fired when cell is left.
3. Use the CellContentClick event: It''s most appropriate. Fires when checkstate is changed.

Note that all these events are fired for all types of columns & not just checkbox columns. So on event, you should check the column type & then check the state.


您可以使用两种方法添加要查找的事件.每当用户访问单元格进行编辑时,第一个事件将添加事件:
You can sort of add the event you are looking for with two methods. The first one will add the the event whenever the user accesses the cell for editing:
Private Sub gvMast_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles gvMast.EditingControlShowing
'This event will setup an event handler for the
'Status combobox column in the grid
'and activate that event handler for the selected combobox.

        Dim cboTemp As ComboBox = CType(e.Control, ComboBox)
        'Remove the handler before adding it to ensure that
        'the event will only be run once
        RemoveHandler cboTemp.SelectionChangeCommitted, AddressOf StatusComboBox_SelectionChangeCommitted
        'Add the handler to the StatusComboBox_SelectionChangeCommitted
        'method, this method will ensure
        'that the event will only be called after the user
        'has selected a different code from the
        'databound status combobox column
        AddHandler cboTemp.SelectionChangeCommitted, AddressOf StatusComboBox_SelectionChangeCommitted

    End Sub



第二个将执行您要放入选择更改事件中的任务,并且必须与第一个中指向的AddressOf方法具有相同的名称:



The second will perform the task you wanted to put in the selection change event and must have the same name as the AddressOf method you point to in the first one:

Private Sub StatusComboBox_SelectionChangeCommitted(ByVal sender As Object, ByVal e As EventArgs)

    'Add code here to reset your column 2 the way you want

End Sub



---编辑---
我忘了提到在第二种方法中您还没有更改单元格的值...因此,如果您想要该单元格的旧值,您将像这样获得它:



---EDIT---
I forgot to mention that inside that second method you haven''t yet changed the cell value...so if you want the old value of the cell you would get it like this:

Dim strCurrentMastStatus As String = gvMast.SelectedRows(0).Cells(strColumnName).Value



要访问用户选择的NEW值,您可以使用以下代码:



And to access the NEW value that the user has selected you would use this:

Dim cboTemp As ComboBox = CType(sender, ComboBox)
cboTemp.SelectedValue


这篇关于什么甚至可以用来访问datagridview组合框的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆