473,396 Members | 1,992 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,396 software developers and data experts.

Custom DataGRidComboBoxStyle DataSource Problems

I have a general DataGridComboBoxColumn that I built using the Example in
the .NET 2003 Combined Collection help file (that was a data time picker).

I am able to assign a data source and display / value members so the
ComboBox is data bound and that works, to a point. What generally works is
the ComboBox get's populated and the ComboBox shows itself when the
appropriate column/row is selected. When the ComboBoxColumn isn't selected
it displays the correct text value (not the related key id value). Alls
cool, until I bind with a DataSet that contains multiple tables related with
DataRelations.

If there are multiple rows, The last row selected properly displays it's
combobox values / or data values. The other rows display blanks. (I set the
comboboxcolumn to display blanks when it can't find the correct value in the
dataset/table/relation.)
I believe this is because of the DataRelation. There is relational data
between on column and another, I.e. a customer ship to location applies to a
single customer. When the last selected row is customer Ford, then the
Chrysler records display blanks in the customer ship to .

Because of the DataRelation it is limiting the data that each combo box is
privy to. And every combo box (shipto's) shares the data source, I believe.

Anyone have any good ideas on how to 'fix' this anomoly? Any help is greatly
appreciated.

Best Regards,

Rick
Mar 1 '06 #1
3 1374
Hi,

http://www.vb-tips.com/default.aspx?...6-7320e41e6d05

Ken
------------------
"Richard Ryerson" <rj*******@xyzneo.rr.com> wrote in message
news:Ph********************@tornado.ohiordc.rr.com ...
I have a general DataGridComboBoxColumn that I built using the Example in
the .NET 2003 Combined Collection help file (that was a data time picker).

I am able to assign a data source and display / value members so the
ComboBox is data bound and that works, to a point. What generally works is
the ComboBox get's populated and the ComboBox shows itself when the
appropriate column/row is selected. When the ComboBoxColumn isn't selected
it displays the correct text value (not the related key id value). Alls
cool, until I bind with a DataSet that contains multiple tables related
with
DataRelations.

If there are multiple rows, The last row selected properly displays it's
combobox values / or data values. The other rows display blanks. (I set
the
comboboxcolumn to display blanks when it can't find the correct value in
the
dataset/table/relation.)
I believe this is because of the DataRelation. There is relational data
between on column and another, I.e. a customer ship to location applies to
a
single customer. When the last selected row is customer Ford, then the
Chrysler records display blanks in the customer ship to .

Because of the DataRelation it is limiting the data that each combo box is
privy to. And every combo box (shipto's) shares the data source, I
believe.

Anyone have any good ideas on how to 'fix' this anomoly? Any help is
greatly
appreciated.

Best Regards,

Rick

Mar 1 '06 #2
Yeah, I am able to display the "words" but state is being lost when selected
"row" changes in the datagrid, due to the relation performing it's job. I
need a viable way to save previous states and call upon that.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:eO**************@TK2MSFTNGP12.phx.gbl...
Hi,

http://www.vb-tips.com/default.aspx?...6-7320e41e6d05
Ken
------------------
"Richard Ryerson" <rj*******@xyzneo.rr.com> wrote in message
news:Ph********************@tornado.ohiordc.rr.com ...
I have a general DataGridComboBoxColumn that I built using the Example in
the .NET 2003 Combined Collection help file (that was a data time picker).
I am able to assign a data source and display / value members so the
ComboBox is data bound and that works, to a point. What generally works is the ComboBox get's populated and the ComboBox shows itself when the
appropriate column/row is selected. When the ComboBoxColumn isn't selected it displays the correct text value (not the related key id value). Alls
cool, until I bind with a DataSet that contains multiple tables related
with
DataRelations.

If there are multiple rows, The last row selected properly displays it's
combobox values / or data values. The other rows display blanks. (I set
the
comboboxcolumn to display blanks when it can't find the correct value in
the
dataset/table/relation.)
I believe this is because of the DataRelation. There is relational data
between on column and another, I.e. a customer ship to location applies to a
single customer. When the last selected row is customer Ford, then the
Chrysler records display blanks in the customer ship to .

Because of the DataRelation it is limiting the data that each combo box is privy to. And every combo box (shipto's) shares the data source, I
believe.

Anyone have any good ideas on how to 'fix' this anomoly? Any help is
greatly
appreciated.

Best Regards,

Rick


Mar 2 '06 #3
Here is the scenario.

Customers (Id, Name)
-------------
1, Ford
2, Chrysler

ShipTos (Id, CustId, Location)
---------
1, 1, XYZ
2, 1, PDQ
3, 2, FAQ
4, 2, ROF

There is a relation between Customers and ShipTos (Customers.Id ->
ShipTos.CustId)

Now main DataTable (Releases) contains info pertaining to Customers and
ShipTos

Releases (Id, CustId, ShipToId, Qty)
----------
1, 1, 1, 5000 (1, Ford, XYZ, 5000)
2, 2, 4, 2500 (2, Chrysler, ROF, 2500)

When the data grid first displays, it only displays complete information for
the second row, because this is the last row in the grid, and therefore the
last DataRelation view set i'll call it. The First record does not display
correctly because it's data is violating the DataRelation constraints.
(ShipTo XYZ does not relate to Chrysler). So, that column gets displayed as
a blank, because to display the 'word' you must traverse or find the 'word'
by the key (1) in the current view.

It appears that each ComboBox 'shares' it's properties / data whatever
regardless of the row. I need a way to search the correct Relation or
remember (bad code) the previous data relation information. I've tried
storing the data/state in a hashtable, but it seems to not work.

Here is the code for the ComboBoxColumn. It needs to be as extendable /
useful as possible. Meaning I can't design this comboboxstyle to work ONLY
in this situation.

Best regards,

Rick

Imports System.ComponentModel

Public Class DataGridComboBoxColumn

Inherits DataGridColumnStyle

Private _isEditing As Boolean = False

Private WithEvents _comboBox As ComboBox

Private _dataSource As Object

Private _dataMember As String

Private _valueMember As String

Private _displayMember As String

Private _lists As Hashtable

Protected Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)

Select Case e.PropertyName

Case "DataSource"

_comboBox.DataSource = _dataSource

Case "ValueMember"

If _dataMember Is Nothing Then

_comboBox.ValueMember = _valueMember

Else

_comboBox.ValueMember = String.Format("{0}.{1}", _dataMember, _valueMember)

End If

Case "DisplayMember"

If _dataMember Is Nothing Then

_comboBox.DisplayMember = _displayMember

Else

_comboBox.DisplayMember = String.Format("{0}.{1}", _dataMember,
_displayMember)

End If

End Select

Invalidate()

End Sub

Public ReadOnly Property DataBindings() As ControlBindingsCollection

Get

Return _comboBox.DataBindings

End Get

End Property

Public Property DataSource() As Object

Get

Return _dataSource

End Get

Set(ByVal Value As Object)

_dataSource = Value

OnPropertyChanged(New PropertyChangedEventArgs("DataSource"))

End Set

End Property

Public Property ValueMember() As String

Get

Return _valueMember

End Get

Set(ByVal Value As String)

_valueMember = Value

OnPropertyChanged(New PropertyChangedEventArgs("ValueMember"))

End Set

End Property

Public Property DisplayMember() As String

Get

Return _displayMember

End Get

Set(ByVal Value As String)

_displayMember = Value

OnPropertyChanged(New PropertyChangedEventArgs("DisplayMember"))

End Set

End Property

Public Property DataMember() As String

Get

Return _dataMember

End Get

Set(ByVal Value As String)

_dataMember = Value

OnPropertyChanged(New PropertyChangedEventArgs("DataMember"))

End Set

End Property

Public Sub New()

_comboBox = New ComboBox

_lists = New Hashtable

_comboBox.Visible = False

End Sub

Protected Overrides Sub Abort(ByVal rowNum As Integer)

_isEditing = False

DataGridTableStyle.DataGrid.Invalidate(_comboBox.B ounds)

End Sub

Protected Overrides Function Commit(ByVal dataSource As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Boolean

_comboBox.Bounds = Rectangle.Empty

If Not _isEditing Then

Return True

End If

_isEditing = False

Try

Dim value As Object

value = _comboBox.SelectedValue

If NullText.Equals(value) Then

value = System.Convert.DBNull

End If

SetColumnValueAtRow(dataSource, rowNum, value)

Catch ex As Exception

End Try

DataGridTableStyle.DataGrid.Invalidate(_comboBox.B ounds)

Return True

End Function

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)

Dim value As Object = GetText(GetColumnValueAtRow(source, rowNum))

If cellIsVisible Then

_comboBox.Bounds = New Rectangle(bounds.X + 2, bounds.Y + 2, bounds.Width -
4, bounds.Height - 4)

_comboBox.Visible = True

Else

_comboBox.Visible = False

End If

If _comboBox.Visible Then

DataGridTableStyle.DataGrid.Invalidate(bounds)

End If

End Sub

Protected Overrides Function GetMinimumHeight() As Integer

Return _comboBox.PreferredHeight + 4

End Function

Protected Overrides Function GetPreferredHeight(ByVal g As
System.Drawing.Graphics, ByVal value As Object) As Integer

Return _comboBox.PreferredHeight + 4

End Function

Protected Overrides Function GetPreferredSize(ByVal g As
System.Drawing.Graphics, ByVal value As Object) As System.Drawing.Size

Return New Size(_comboBox.Width + 4, _comboBox.PreferredHeight + 4)

End Function

Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics,
ByVal bounds As System.Drawing.Rectangle, ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer)

Paint(g, bounds, [source], rowNum, False)

End Sub

Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics,
ByVal bounds As System.Drawing.Rectangle, ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal
alignToRight As Boolean)

Paint(g, bounds, [source], rowNum, Brushes.Red, Brushes.Blue, alignToRight)

End Sub

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)

Dim value As Object = GetColumnValueAtRow([source], rowNum)

Dim rect As Rectangle = bounds

Dim s As String = Nothing

Dim displayMem As String

Dim valueMem As String

If _lists(rowNum) Is Nothing Then

Dim col(_comboBox.Items.Count - 1) As Object

_comboBox.Items.CopyTo(col, 0)

_lists.Add(rowNum, col)

End If

'loop through the items of the combo box

'this items collection seems to be shared

'between all the instances of the same

'column of combo boxes.

Dim col2() As Object = _lists(rowNum)

For Each drv As DataRowView In _comboBox.Items

If _valueMember.IndexOf(_dataMember) > -1 Then

'remove the Parent.Relation. from the value member

valueMem = _valueMember.Replace(_dataMember, "").Remove(0, 1)

Else

valueMem = _valueMember

End If

If _displayMember.IndexOf(_dataMember) > -1 Then

'remove the Parent.Relation. from the display member

displayMem = _displayMember.Replace(_dataMember, "").Remove(0, 1)

Else

displayMem = _displayMember

End If

'make sure it's not a added row

If Not value Is Nothing AndAlso Not value Is System.DBNull.Value Then

If drv(valueMem) = value Then

Try

s = drv(displayMem)

Catch ex As Exception

s = value

End Try

Exit For

End If

Else

s = Me.NullText

Exit For

End If

Next

g.FillRectangle(backBrush, rect)

rect.Offset(0, 2)

rect.Height -= 2

If Not s Is Nothing Then

If value Is Nothing Then

s = NullText

End If

Try

g.DrawString(s.ToString, Me.DataGridTableStyle.DataGrid.Font, foreBrush,
RectangleF.FromLTRB(rect.X, rect.Y, rect.Right, rect.Bottom))

Catch ex As Exception

Debug.WriteLine(ex.ToString)

End Try

End If

End Sub

Protected Overrides Sub SetDataGridInColumn(ByVal value As DataGrid)

MyBase.SetDataGridInColumn(value)

If Not (_comboBox.Parent Is Nothing) Then

_comboBox.Parent.Controls.Remove(_comboBox)

End If

If Not (value Is Nothing) Then

value.Controls.Add(_comboBox)

End If

End Sub

Public Overrides Property Width() As Integer

Get

Return MyBase.Width

End Get

Set(ByVal Value As Integer)

MyBase.Width = Value

_comboBox.Width = Value - 4

End Set

End Property

Private Function GetText(ByVal value As Object) As String

If value Is System.DBNull.Value Then

Return Me.NullText

Else

If Not value Is Nothing Then

Return value.ToString

Else

Return String.Empty

End If

End If

End Function

Private Sub _comboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles _comboBox.SelectedIndexChanged

_isEditing = True

MyBase.ColumnStartedEditing(_comboBox)

End Sub

End Class


Best regards,

Rick
Mar 2 '06 #4

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

Similar topics

3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
0
by: perspolis | last post by:
Hi all I used one of DataGridComboBoxStyle in www.CodeProject.com but the problem I faced was that if I type one of items in combobox ,then press enter it lose that item. instead I have to...
1
by: Marty Cruise | last post by:
I have a custom collection which contains instances of a custom class. With me so far? OK, now I set the datasource of a combobox to the collection, having overridden the ToString() function of...
2
by: Don | last post by:
I've been trying to create a custom collection that can be bound to a combobox via the DataSource property, but I can't seem to get it to work. I've created a class that implements IList, and it...
1
by: nate axtell | last post by:
In VB .Net I made a custom CheckBox column style (for the Datagrid control) that maps to two DataTable columns , one it uses for the Checked status and the other it uses for the Enabled status. I am...
0
by: Eric Dreksler | last post by:
Hi, I'm trying to make a custom implementation of ListControl, where I pass in a control type (based off a MustInherit UserControl) and a DataSource. Public Class PrettyControlList Inherits...
3
by: Richard Ryerson | last post by:
I have a general DataGridComboBoxColumn that I built using the Example in the .NET 2003 Combined Collection help file (that was a data time picker). I am able to assign a data source and display...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
5
by: Mark Olbert | last post by:
How do I get the DataPager and ListView to play nice together when I use a custom datasource? In my webpage, I use linq to pull data from a SqlServer database and assign the resulting...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.