473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

special DataGridComboBoxColumn

hi,

for my DataGrids I'm using DataGridComboBoxColumns (the simple class example
found everywhere in the internet) for the user to select the values. this
works quite good.

now for one DataGrid I need the data in the ComboBox to depend on other
values in the row, so i have to reload the DataSource from the DB.

for example: user selects a product from group A, the ComboBox should select
and show all possible errors for group A.

i tried to overwrite the DataGridComboBoxColumn class and build the reload
into the GetDataValue function, but if i select an entry of the ComboBox, it
immediatly changes back to NULL.
does anybody have an idea or another solution for this?

thx for any help
netracer
Nov 21 '05 #1
4 2305
Hi netracer,

I achieved this with the DacDataGridComboBox class (below).

This code sets a filter for the data in the (target) combo based on the
value selected in the source combo but you should be able to adapt to meet
your needs.

in this case:
Set the ComboFilterColumn property to the name of the column the combo is
dependant on
Set the ComboFilterField property to name of the field (DataColumn) that you
want to filter.

Doug

Public Class DacDataGridComboBox

Inherits DataGridTextBoxColumn

Public ColumnComboBox As NoKeyUpCombo

Public Shared _RowCount As Integer

Private _source As System.Windows.Forms.CurrencyManager

Private _RowNum As Integer

Private _isEditing As Boolean

Private CurrentValue As Object

Private stReadOnlyColName As String

Private stReadOnlyColOperator As String

Private stReadOnlyColParameter As String

Private stDependantField As String

Private stSortField As String

Private stComboFilterField As String

Private stComboFilterColumn As String

Private stComboSortField As String

'Property for testing another column to set ReadOnly status

Public Property ReadOnlyColName() As Object

'Property to Determine which Row to test

Get

Return stReadOnlyColName

End Get

Set(ByVal Value As Object)

stReadOnlyColName = Value & ""

End Set

End Property

'Property for testing another column to set ReadOnly status

Public Property ReadOnlyColOperator() As String

'Property to Determine which Row to test

Get

Return stReadOnlyColOperator

End Get

Set(ByVal Value As String)

stReadOnlyColOperator = Value

End Set

End Property

'Property for testing another column to set ReadOnly status

Public Property ReadOnlyColParameter() As String

'Test value

Get

Return stReadOnlyColParameter

End Get

Set(ByVal Value As String)

stReadOnlyColParameter = Value

End Set

End Property

'Property for Resetting a another column if combo changes value

Public Property DependantField() As String

'Combo Feild to Filter

Get

Return stDependantField

End Get

Set(ByVal Value As String)

stDependantField = Value

End Set

End Property

'Property for filtering combo on another field

Public Property ComboFilterField() As String

'Field to Reset

Get

Return stComboFilterField

End Get

Set(ByVal Value As String)

stComboFilterField = Value

End Set

End Property

'Property for Resetting a another column if combo changes value

Public Property ComboFilterColumn() As String

'Test value

Get

Return stComboFilterColumn

End Get

Set(ByVal Value As String)

stComboFilterColumn = Value

End Set

End Property

'Property for Resetting a another column if combo changes value

Public Property ComboSortField() As String

'Test value

Get

Return stComboSortField

End Get

Set(ByVal Value As String)

stComboSortField = Value

End Set

End Property

Public Sub New()

_source = Nothing

_isEditing = False

_RowCount = -1

ColumnComboBox = New NoKeyUpCombo

ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList

AddHandler ColumnComboBox.Leave, AddressOf LeaveComboBox

AddHandler ColumnComboBox.SelectionChangeCommitted, _

AddressOf ComboStartEditing

End Sub

'Hide ComboBox if scrolling

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

If ColumnComboBox.Visible Then

ColumnComboBox.Hide()

End If

End Sub

'Set Flag IsEditing

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

_isEditing = True

MyBase.ColumnStartedEditing(sender)

End Sub

'Reset Flag IsEditing

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

'Over ride Paint Method

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, _

ByVal bounds As Rectangle, ByVal source As CurrencyManager, _

ByVal rowNum As Integer, ByVal backBrush As Brush, _

ByVal foreBrush As Brush, ByVal alignToRight As Boolean)

If Not Me.ReadOnly Then

Dim colBackCol As Color = Me.DataGridTableStyle.BackColor

Dim colAltBackCol As Color = Me.DataGridTableStyle.AlternatingBackColor

Dim bshBackCellColour, bshAltBackCellColour As SolidBrush

bshBackCellColour = New SolidBrush(colBackCol)

bshAltBackCellColour = New SolidBrush(colAltBackCol)

If rowNum / 2 > Int(rowNum / 2) Then

backBrush = bshBackCellColour

Else

backBrush = bshAltBackCellColour

End If

End If

MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)

End Sub

Protected Overloads Overrides Sub Edit _

(ByVal [source] As System.Windows.Forms.CurrencyManager, _

ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, _

ByVal [readOnly] As Boolean, ByVal instantText As String, _

ByVal cellIsVisible As Boolean)

MyBase.Edit([source], rowNum, bounds, [readOnly], _

instantText, cellIsVisible)

_RowNum = rowNum

_source = [source]

If Not Me.ReadOnly Then

With ColumnComboBox

If Not (stComboFilterField) Is Nothing And _

Not (stComboFilterColumn) Is Nothing Then

Dim stFilter As String

Dim drv As DataRowView = CType([source].Current, DataRowView)

Dim dv As DataView = CType(Me.ColumnComboBox.DataSource, DataView)

stFilter = ComboFilterField & "='" & drv(ComboFilterColumn) & "'"

dv.RowFilter = stFilter

If Not (stComboSortField) Is Nothing Then

dv.Sort = stComboSortField

End If

..DataSource = dv

End If

..Parent = Me.TextBox.Parent

..Location = Me.TextBox.Location

..Size = New Size(Me.TextBox.Size.Width + 15, Me.TextBox.Size.Height)

..SelectedIndex = .FindStringExact(Me.TextBox.Text)

If Me.TextBox.Text.Length > 0 Then

..Text = Me.TextBox.Text

Else

..DroppedDown = True

End If

Me.TextBox.Visible = False

..Visible = True

AddHandler Me.DataGridTableStyle.DataGrid.Scroll, _

AddressOf HandleScroll

..BringToFront()

..Focus()

End With

End If

End Sub

Protected Overrides Function Commit _

(ByVal datasource As System.Windows.Forms.CurrencyManager, _

ByVal rowNum As Integer) As Boolean

If _isEditing Then

_isEditing = False

SetColumnValueAtRow(datasource, rowNum, ColumnComboBox.Text)

End If

Return True

End Function

Protected Overrides Sub ConcedeFocus()

MyBase.ConcedeFocus()

End Sub

Protected Overrides Function GetColumnValueAtRow _

(ByVal [source] As System.Windows.Forms.CurrencyManager, _

ByVal rowNum As Integer) As Object

'Get value for Whs for this line

Dim s As Object = MyBase.GetColumnValueAtRow([source], rowNum)

'Get the current row

Dim drv As DataRowView = CType([source].Current, DataRowView)

CurrentValue = s

'Test and Set Read Only Status if Column follows rule

Dim mTestCol As New DacTestDRColumn

With mTestCol

..DefReadOnlyFlag = Me.ReadOnly

..ReadOnlyColName = stReadOnlyColName

..ReadOnlyColOperator = stReadOnlyColOperator

..ReadOnlyColParameter = stReadOnlyColParameter

..ReadOnlyDrv = drv

Me.ReadOnly = .DacTest

End With

Return s

End Function

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

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)

Else

s = DBNull.Value

End If

MyBase.SetColumnValueAtRow([source], rowNum, s)

If CurrentValue Is DBNull.Value Then

CurrentValue = ""

End If

If s Is DBNull.Value Then

s = ""

End If

Dim drv As DataRowView = CType([source].Current, DataRowView)

If CurrentValue <> s And Not (stDependantField) Is Nothing Then

drv(stDependantField) = ""

End If

End Sub

End Class

#End Region
"NetRacer" <ne******@netspeedway.net> wrote in message
news:de*************@news.t-online.com...
hi,

for my DataGrids I'm using DataGridComboBoxColumns (the simple class example found everywhere in the internet) for the user to select the values. this
works quite good.

now for one DataGrid I need the data in the ComboBox to depend on other
values in the row, so i have to reload the DataSource from the DB.

for example: user selects a product from group A, the ComboBox should select and show all possible errors for group A.

i tried to overwrite the DataGridComboBoxColumn class and build the reload
into the GetDataValue function, but if i select an entry of the ComboBox, it immediatly changes back to NULL.
does anybody have an idea or another solution for this?

thx for any help
netracer

Nov 21 '05 #2
Hi Doug,

if I'm reading your code right, this is a ComboBoxColumn that changes the
filter on another column if changed?!

so, I have four problems to use your code:
- my column with the dependend value is not a ComboBoxColumn, but another
user defined column type
- the value my ComboBox depends on, is not directly in the row. I get it
through a function with another value of the row (like >
GetProductGroupID(ProductID as Integer) as Integer < where the ProductID is
in the row)
- I cannot use a rowfilter, because of the big amount of data. I must redo
a select with 'where' if the dependend value changes
- in your GetValueData you are creating a new object from the type
"DacTestDRColumn". what does this type? how is it defined?

Do you have an(other) idea for solution of my problem(s)?

However, thanx for your help... I will try to adapt your code for my uses if
possible.
Greetz
netracer

"Doug Bell" <Po*********@vodaphone.com.au> schrieb im Newsbeitrag
news:O7**************@TK2MSFTNGP15.phx.gbl...
Hi netracer,

I achieved this with the DacDataGridComboBox class (below).

This code sets a filter for the data in the (target) combo based on the
value selected in the source combo but you should be able to adapt to meet
your needs.

in this case:
Set the ComboFilterColumn property to the name of the column the combo is
dependant on
Set the ComboFilterField property to name of the field (DataColumn) that
you
want to filter.

Doug

Public Class DacDataGridComboBox

Inherits DataGridTextBoxColumn

Public ColumnComboBox As NoKeyUpCombo

Public Shared _RowCount As Integer

Private _source As System.Windows.Forms.CurrencyManager

Private _RowNum As Integer

Private _isEditing As Boolean

Private CurrentValue As Object

Private stReadOnlyColName As String

Private stReadOnlyColOperator As String

Private stReadOnlyColParameter As String

Private stDependantField As String

Private stSortField As String

Private stComboFilterField As String

Private stComboFilterColumn As String

Private stComboSortField As String

'Property for testing another column to set ReadOnly status

Public Property ReadOnlyColName() As Object

'Property to Determine which Row to test

Get

Return stReadOnlyColName

End Get

Set(ByVal Value As Object)

stReadOnlyColName = Value & ""

End Set

End Property

'Property for testing another column to set ReadOnly status

Public Property ReadOnlyColOperator() As String

'Property to Determine which Row to test

Get

Return stReadOnlyColOperator

End Get

Set(ByVal Value As String)

stReadOnlyColOperator = Value

End Set

End Property

'Property for testing another column to set ReadOnly status

Public Property ReadOnlyColParameter() As String

'Test value

Get

Return stReadOnlyColParameter

End Get

Set(ByVal Value As String)

stReadOnlyColParameter = Value

End Set

End Property

'Property for Resetting a another column if combo changes value

Public Property DependantField() As String

'Combo Feild to Filter

Get

Return stDependantField

End Get

Set(ByVal Value As String)

stDependantField = Value

End Set

End Property

'Property for filtering combo on another field

Public Property ComboFilterField() As String

'Field to Reset

Get

Return stComboFilterField

End Get

Set(ByVal Value As String)

stComboFilterField = Value

End Set

End Property

'Property for Resetting a another column if combo changes value

Public Property ComboFilterColumn() As String

'Test value

Get

Return stComboFilterColumn

End Get

Set(ByVal Value As String)

stComboFilterColumn = Value

End Set

End Property

'Property for Resetting a another column if combo changes value

Public Property ComboSortField() As String

'Test value

Get

Return stComboSortField

End Get

Set(ByVal Value As String)

stComboSortField = Value

End Set

End Property

Public Sub New()

_source = Nothing

_isEditing = False

_RowCount = -1

ColumnComboBox = New NoKeyUpCombo

ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList

AddHandler ColumnComboBox.Leave, AddressOf LeaveComboBox

AddHandler ColumnComboBox.SelectionChangeCommitted, _

AddressOf ComboStartEditing

End Sub

'Hide ComboBox if scrolling

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

If ColumnComboBox.Visible Then

ColumnComboBox.Hide()

End If

End Sub

'Set Flag IsEditing

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

_isEditing = True

MyBase.ColumnStartedEditing(sender)

End Sub

'Reset Flag IsEditing

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

'Over ride Paint Method

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, _

ByVal bounds As Rectangle, ByVal source As CurrencyManager, _

ByVal rowNum As Integer, ByVal backBrush As Brush, _

ByVal foreBrush As Brush, ByVal alignToRight As Boolean)

If Not Me.ReadOnly Then

Dim colBackCol As Color = Me.DataGridTableStyle.BackColor

Dim colAltBackCol As Color = Me.DataGridTableStyle.AlternatingBackColor

Dim bshBackCellColour, bshAltBackCellColour As SolidBrush

bshBackCellColour = New SolidBrush(colBackCol)

bshAltBackCellColour = New SolidBrush(colAltBackCol)

If rowNum / 2 > Int(rowNum / 2) Then

backBrush = bshBackCellColour

Else

backBrush = bshAltBackCellColour

End If

End If

MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush,
alignToRight)

End Sub

Protected Overloads Overrides Sub Edit _

(ByVal [source] As System.Windows.Forms.CurrencyManager, _

ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, _

ByVal [readOnly] As Boolean, ByVal instantText As String, _

ByVal cellIsVisible As Boolean)

MyBase.Edit([source], rowNum, bounds, [readOnly], _

instantText, cellIsVisible)

_RowNum = rowNum

_source = [source]

If Not Me.ReadOnly Then

With ColumnComboBox

If Not (stComboFilterField) Is Nothing And _

Not (stComboFilterColumn) Is Nothing Then

Dim stFilter As String

Dim drv As DataRowView = CType([source].Current, DataRowView)

Dim dv As DataView = CType(Me.ColumnComboBox.DataSource, DataView)

stFilter = ComboFilterField & "='" & drv(ComboFilterColumn) & "'"

dv.RowFilter = stFilter

If Not (stComboSortField) Is Nothing Then

dv.Sort = stComboSortField

End If

.DataSource = dv

End If

.Parent = Me.TextBox.Parent

.Location = Me.TextBox.Location

.Size = New Size(Me.TextBox.Size.Width + 15, Me.TextBox.Size.Height)

.SelectedIndex = .FindStringExact(Me.TextBox.Text)

If Me.TextBox.Text.Length > 0 Then

.Text = Me.TextBox.Text

Else

.DroppedDown = True

End If

Me.TextBox.Visible = False

.Visible = True

AddHandler Me.DataGridTableStyle.DataGrid.Scroll, _

AddressOf HandleScroll

.BringToFront()

.Focus()

End With

End If

End Sub

Protected Overrides Function Commit _

(ByVal datasource As System.Windows.Forms.CurrencyManager, _

ByVal rowNum As Integer) As Boolean

If _isEditing Then

_isEditing = False

SetColumnValueAtRow(datasource, rowNum, ColumnComboBox.Text)

End If

Return True

End Function

Protected Overrides Sub ConcedeFocus()

MyBase.ConcedeFocus()

End Sub

Protected Overrides Function GetColumnValueAtRow _

(ByVal [source] As System.Windows.Forms.CurrencyManager, _

ByVal rowNum As Integer) As Object

'Get value for Whs for this line

Dim s As Object = MyBase.GetColumnValueAtRow([source], rowNum)

'Get the current row

Dim drv As DataRowView = CType([source].Current, DataRowView)

CurrentValue = s

'Test and Set Read Only Status if Column follows rule

Dim mTestCol As New DacTestDRColumn

With mTestCol

.DefReadOnlyFlag = Me.ReadOnly

.ReadOnlyColName = stReadOnlyColName

.ReadOnlyColOperator = stReadOnlyColOperator

.ReadOnlyColParameter = stReadOnlyColParameter

.ReadOnlyDrv = drv

Me.ReadOnly = .DacTest

End With

Return s

End Function

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

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)

Else

s = DBNull.Value

End If

MyBase.SetColumnValueAtRow([source], rowNum, s)

If CurrentValue Is DBNull.Value Then

CurrentValue = ""

End If

If s Is DBNull.Value Then

s = ""

End If

Dim drv As DataRowView = CType([source].Current, DataRowView)

If CurrentValue <> s And Not (stDependantField) Is Nothing Then

drv(stDependantField) = ""

End If

End Sub

End Class

#End Region
"NetRacer" <ne******@netspeedway.net> wrote in message
news:de*************@news.t-online.com...
hi,

for my DataGrids I'm using DataGridComboBoxColumns (the simple class

example
found everywhere in the internet) for the user to select the values. this
works quite good.

now for one DataGrid I need the data in the ComboBox to depend on other
values in the row, so i have to reload the DataSource from the DB.

for example: user selects a product from group A, the ComboBox should

select
and show all possible errors for group A.

i tried to overwrite the DataGridComboBoxColumn class and build the
reload
into the GetDataValue function, but if i select an entry of the ComboBox,

it
immediatly changes back to NULL.
does anybody have an idea or another solution for this?

thx for any help
netracer


Nov 21 '05 #3
Hi,

The function DacTestDRColumn (I have added below) is for another property
that sets the columns ReadOnly property dependant on another columns value.

I assume you could call your function in a similar way to how I call
DacTestDRColumn .
Public Class DacTestDRColumn

Public DefReadOnlyFlag As Boolean

Public ReadOnlyColName As String

Public ReadOnlyColOperator As String

Public ReadOnlyColParameter As String

Public ReadOnlyDrv As DataRowView

Public Function DacTest() As Boolean

Dim fReadOnly As Boolean = DefReadOnlyFlag

'Determine operator

Try

If Not (ReadOnlyColName) Is Nothing And _

Not (ReadOnlyColOperator) Is Nothing And _

Not (ReadOnlyColParameter) Is Nothing Then

Try

Select Case ReadOnlyColOperator

Case Is = "="

'Set to Read Only if the value in the selected Column = the passed value

fReadOnly = ReadOnlyDrv(ReadOnlyColName).ToString =
ReadOnlyColParameter.ToString

Case Is = ">"

'Set to Read Only if the value in the selected Column > the passed value

fReadOnly = ReadOnlyDrv(ReadOnlyColName).ToString >
ReadOnlyColParameter.ToString

Case Is = "<"

'Set to Read Only if the value in the selected Column < the passed value

fReadOnly = ReadOnlyDrv(ReadOnlyColName).ToString <
ReadOnlyColParameter.ToString

Case Is = "<>"

'Set to Read Only if the value in the selected Column <> the passed value

fReadOnly = ReadOnlyDrv(ReadOnlyColName).ToString <>
ReadOnlyColParameter.ToString

Case Is = "Like"

'Set to Read Only if the value in the selected Column Like the passed value

fReadOnly = ReadOnlyDrv(ReadOnlyColName).ToString Like ReadOnlyColParameter
& "*"

End Select

Catch

End Try

End If

Catch

End Try

Return fReadOnly

End Function
if I'm reading your code right, this is a ComboBoxColumn that changes the
filter on another column if changed?!
The Combo Box filter is set based on the value selected in a combo box in
another column.

so, I have four problems to use your code:
- my column with the dependend value is not a ComboBoxColumn, but another user defined column type
- the value my ComboBox depends on, is not directly in the row. I get it
through a function with another value of the row (like >
GetProductGroupID(ProductID as Integer) as Integer < where the ProductID is in the row)
Should not matter, you pass to the "ComboBox" Column the column that it is
dependant on.
When you click on the ComboBox Column, it will check the column (specified),
retrieve the value,
run your function and set the combo.

You will need to think about how you handle the situation of the User
changing the source column,
Do you set the combo column to Null?
- I cannot use a rowfilter, because of the big amount of data. I must redo a select with 'where' if the dependend value changes

I guess you mean the Where Clause changes which fields it operates on or
uses multiple fields.
Not sure how I would handle that?
Doug
Nov 21 '05 #4
Hi again,

I don't get it work for my cases.
This is my class:
Public Class DataGridConditionedComboBoxColumn
Inherits DataGridComboBoxColumn 'The default one found anywhere in the
www

Private _da As Data.IDbDataAdapter
Private _cond As String = String.Empty
Private _sql As String = String.Empty
Private _row As Integer = -1
Private _valuefunction As ValueFunctions

Private _condvalue As Object = String.Empty

Public Delegate Function ValueFunctions(ByVal rowNum As Integer) As
Object
Public Sub New()
MyBase.New()
End Sub

Public Property ConditionString() As String
Get
Return _cond
End Get
Set(ByVal Value As String)
_cond = Value
End Set
End Property

Public Property ValueFunction() As ValueFunctions
Get
Return _valuefunction
End Get
Set(ByVal Value As ValueFunctions)
_valuefunction = Value
End Set
End Property

Public Property SQL() As String
Get
Return _sql
End Get
Set(ByVal Value As String)
_sql = Value
End Set
End Property

Public Property DataAdapter() As Data.IDbDataAdapter
Get
Return _da
End Get
Set(ByVal Value As Data.IDbDataAdapter)
_da = Value
End Set
End Property
Protected Overloads Overrides Sub Edit(ByVal [source] As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds
As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText
As String, ByVal cellIsVisible As Boolean)
If Me.ReadOnly Or Me.DataGridTableStyle.ReadOnly Then
Me.TextBox.Visible = False
Exit Sub
End If

MyBase.Edit([source], rowNum, bounds, [readOnly], instantText,
cellIsVisible, True)

_isEditing = True

_rowNum = rowNum
_source = [source]

ColumnComboBox.Parent = Me.TextBox.Parent
ColumnComboBox.Location = Me.TextBox.Location
ColumnComboBox.Size = New Size(Me.TextBox.Size.Width,
ColumnComboBox.Size.Height)

Me.TextBox.Visible = False
ColumnComboBox.Visible = True

ColumnComboBox.SelectedIndex =
ColumnComboBox.FindStringExact(Me.TextBox.Text)

ColumnComboBox.BringToFront()
ColumnComboBox.Focus()
End Sub
Protected Overloads Overrides Function GetColumnValueAtRow(ByVal source
As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Object
Dim dt As DataTable
Dim cond As String
Dim sql As String = _sql
Dim _val As Object

Cursor.Current = Cursors.WaitCursor

Dim value As Object
If Not (IsNothing(_valuefunction)) Then
'call the fuction to get the current value the combobox depends
on
value = _valuefunction.Invoke(rowNum)
Else : value = Nothing
End If

If IsNothing(_condvalue) Then _condvalue = String.Empty
If IsNothing(value) Then value = DBNull.Value

If _row <> rowNum OrElse _condvalue.ToString <> value.ToString Then
_row = rowNum
_condvalue = value

If IsDBNull(value) Then value = Nothing

If _cond.IndexOf("{0}") >= 0 And Not IsNothing(value) Then
cond = String.Format(_cond, value)
sql = sql.Replace("{cond}", cond)
Else
sql = sql.Replace("{cond}", "True")
End If
Try
_da.SelectCommand.CommandText = sql

If IsNothing(ColumnComboBox.DataSource) Then
dt = New DataTable
Dim dv As DataView = dt.DefaultView
ColumnComboBox.DataSource = dv
Else
dt = CType(ColumnComboBox.DataSource, DataView).Table
dt.Clear()
End If

CType(_da, DbDataAdapter).Fill(dt)
_val = CType(source.List,
DataView)(rowNum)(ColumnComboBox.ValueMember)
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
Else
_val = ColumnComboBox.SelectedValue
End If

Dim _dispVal As String = GetDisplayValue(_val).ToString
ColumnComboBox.SelectedIndex =
ColumnComboBox.FindStringExact(_dispVal)

Cursor.Current = Cursors.Default

If Not IsNothing(_val) Then Return _dispVal
Return DBNull.Value

End Function

Function GetDisplayValue(ByVal Value As Object) As Object
Dim i As Integer
Dim dv As DataView = CType(ColumnComboBox.DataSource, DataView)
If IsNothing(dv) Then Return DBNull.Value
Dim rowCount As Integer = dv.Count
Dim s As Object = Value
Dim s1 As Object

If IsNothing(s) Then s = DBNull.Value

While i < rowCount
s1 = dv(i)(Me.ColumnComboBox.ValueMember)
If Not IsDBNull(s1) AndAlso _
Not IsDBNull(s) AndAlso _
s.ToString = s1.ToString Then
Exit While
End If
i = i + 1
End While

If i < rowCount Then
Return dv(i)(Me.ColumnComboBox.DisplayMember)
Else : Return DBNull.Value
End If
End Function
End Class
Can you (or somebody else) help me to get this working?!
Thanx a while,
netracer

"Doug Bell" <Po*********@vodaphone.com.au> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,

The function DacTestDRColumn (I have added below) is for another property
that sets the columns ReadOnly property dependant on another columns
value.

I assume you could call your function in a similar way to how I call
DacTestDRColumn .
Public Class DacTestDRColumn

Public DefReadOnlyFlag As Boolean

Public ReadOnlyColName As String

Public ReadOnlyColOperator As String

Public ReadOnlyColParameter As String

Public ReadOnlyDrv As DataRowView

Public Function DacTest() As Boolean

Dim fReadOnly As Boolean = DefReadOnlyFlag

'Determine operator

Try

If Not (ReadOnlyColName) Is Nothing And _

Not (ReadOnlyColOperator) Is Nothing And _

Not (ReadOnlyColParameter) Is Nothing Then

Try

Select Case ReadOnlyColOperator

Case Is = "="

'Set to Read Only if the value in the selected Column = the passed value

fReadOnly = ReadOnlyDrv(ReadOnlyColName).ToString =
ReadOnlyColParameter.ToString

Case Is = ">"

'Set to Read Only if the value in the selected Column > the passed value

fReadOnly = ReadOnlyDrv(ReadOnlyColName).ToString >
ReadOnlyColParameter.ToString

Case Is = "<"

'Set to Read Only if the value in the selected Column < the passed value

fReadOnly = ReadOnlyDrv(ReadOnlyColName).ToString <
ReadOnlyColParameter.ToString

Case Is = "<>"

'Set to Read Only if the value in the selected Column <> the passed value

fReadOnly = ReadOnlyDrv(ReadOnlyColName).ToString <>
ReadOnlyColParameter.ToString

Case Is = "Like"

'Set to Read Only if the value in the selected Column Like the passed
value

fReadOnly = ReadOnlyDrv(ReadOnlyColName).ToString Like
ReadOnlyColParameter
& "*"

End Select

Catch

End Try

End If

Catch

End Try

Return fReadOnly

End Function
if I'm reading your code right, this is a ComboBoxColumn that changes the
filter on another column if changed?!


The Combo Box filter is set based on the value selected in a combo box in
another column.

so, I have four problems to use your code:
- my column with the dependend value is not a ComboBoxColumn, but

another
user defined column type
- the value my ComboBox depends on, is not directly in the row. I get
it
through a function with another value of the row (like >
GetProductGroupID(ProductID as Integer) as Integer < where the ProductID

is
in the row)


Should not matter, you pass to the "ComboBox" Column the column that it is
dependant on.
When you click on the ComboBox Column, it will check the column
(specified),
retrieve the value,
run your function and set the combo.

You will need to think about how you handle the situation of the User
changing the source column,
Do you set the combo column to Null?
- I cannot use a rowfilter, because of the big amount of data. I must

redo
a select with 'where' if the dependend value changes

I guess you mean the Where Clause changes which fields it operates on or
uses multiple fields.
Not sure how I would handle that?
Doug

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Barry Olly | last post by:
Hi, I'm working on a mini content management system and need help with dealing with special characters. The input are taken from html form which are then stored into a varchar column in...
0
by: Henry | last post by:
I'm trying to underline the header text of a grid column. I've tried using string.format with no results. Any ideas/thoughts would be appreciated. Tks....
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
7
by: arno | last post by:
Hi, I want to search a substring within a string : fonction (str, substr) { if (str.search(substr) != -1) { // do something } }
3
by: jefftyzzer | last post by:
Friends: I have a stored procedure declared as: CREATE PROCEDURE X.Y LANGUAGE SQL DYNAMIC RESULT SETS 1 READS SQL DATA SPECIFIC Y INHERIT SPECIAL REGISTERS
7
by: Ben Finney | last post by:
Howdy all, Ned Batchelder blogged about a debate over checking function parameters, and to what extent dynamic typing should be relied upon. I was one of many who commented, but I wrote what...
5
by: Alex | last post by:
Hi all - Is there a standard way to handle special chars in strings in dotnet? I'm using csharp and having two seperate problems... 1. Passing in args... I need to pass in an arg that...
0
by: dearsaran | last post by:
Hi, I Want a function written for finding the special characters in a emailid.. Suppose, i've a column email in a table and inserting a emailid with any of the special characters then if i...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.