Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Comboboxcolumn

Status
Not open for further replies.

Reinout

IS-IT--Management
Feb 22, 2004
48
BE
I have a question about a datagrid with custom columns. I built a comboboxcolumn, everything's working fine, accept one thing.
Everytime I change a value in a combobox and I remain in the same line of the datagrid, the custom column in the first line shows the same value as the last selected. As soon as I change rows the first row returns to its original value.
I can't think of an error, I debugged my custom column and it never changes the value in the first row, so I really have no idea about what's going on.

Some code :


Private Sub LeaveComboBox(ByVal sender As Object, ByVal e As EventArgs)
If _isEditing Then
SetColumnValueAtRow(_source, _rowNum, ColumnComboBox.Text)
_isEditing = False
Invalidate()
End If
ColumnComboBox.Hide()
AddHandler Me.DataGridTableStyle.DataGrid.Scroll, New EventHandler(AddressOf HandleScroll)
End Sub 'LeaveComboBox

Protected Overrides Sub SetColumnValueAtRow(ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal value As Object)
Dim s As Object = value

Dim dv As DataView = CType(Me.ColumnComboBox.DataSource, DataView)
Dim rowCount As Integer = dv.Count
Dim i As Integer = 0
Dim s1 As Object

'if things are slow, you could order your dataview
'& use binary search instead of this linear one
While i < rowCount
s1 = dv(i)(Me.ColumnComboBox.DisplayMember)
If (Not s1 Is DBNull.Value) AndAlso _
s = s1 Then
Exit While
End If
i = i + 1
End While
If i < rowCount Then
s = dv(i)(Me.ColumnComboBox.ValueMember)
'MsgBox(s)
Else
s = DBNull.Value
End If
MyBase.SetColumnValueAtRow([source], rowNum, s)
End Sub 'SetColumnValueAtRow
 
That's not a sollution, my datagrid/dataset only updates the database on rowchange, so reshowing the form means I return to the original value of the combobox, even on the row I just changed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top