SQLCE bound control with Null value

G

Graeme Richardson

Hi, two tables with one-to-none,one or many relational integrity enforced.

I've populated a combobox using an ArrayList object

Dim strSQL As String = "SELECT uidSampleArea, SampleArea FROM tlkpSampleArea
ORDER BY SampleArea"
mdsDataSet = mCDatabase.getDataSet(strSQL)

Dim al As ArrayList = New ArrayList
al.Add(New clsSampleArea)

Dim dt As DataTable = mdsDataSet.Tables(0)
For Each dr As DataRow In dt.Rows
al.Add(New clsSampleArea(dr))
Next

' Fill ComboBox
rcboComboBox.Items.Clear() ' Remove history
rcboComboBox.DataSource = al
rcboComboBox.ValueMember = "uidSampleArea" ' String field
rcboComboBox.DisplayMember = "SampleArea" ' String field

How should I populate a combobox to have a Null value at the top of the list
(rather than zero length string)?
Alternatively, is there a better way to do this?

Thanks, Graeme.
 
G

Graeme Richardson

Private mdrDataRow as DataRow

Public Property uidSampleArea() As String
Get
Try
uidSampleArea = mdrDataRow.Item("uidSampleArea").ToString
Catch ex As Exception
'
uidSampleArea = ""
End Try
End Get
Set(ByVal Value As String)
mdrDataRow.Item("uidSampleArea") = Value
End Set
End Property
 
W

W.G. Ryan eMVP

You can add the value you want to appear by adding a datacolumn and setting
its Expression property.

myDataColumn.Expression = "IsNull(RealcolumnName, "NULL");
then just bind to this data column instead
 
G

Graeme Richardson

Hi, I don't know how to use this:
myDataColumn.Expression = "IsNull(RealcolumnName, "NULL");

How do I tie it to the combobox?
Where [in the help files?] can I read more on this technique?

Thanks, Graeme.
 
I

Ilya Tumanov [MS]

First of all, why would you copy rows from DataTable to the ArrayList?
Bind to DataTable directly instead (or create a DataView).
If you do that, you could use DataTable.DefaultView (or DataView you've
created) to sort or filter the data.

To use custom formatting, you can handle Binding.Format and Binding.Parse
events.
You can implement them so NULL values would be shown in whatever way you
want.
There's a sample on how to do that in VS documentation, just look for
Binding class.
Note: make sure you hook up event handlers before binding is added to the
control.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top