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

combo box with 'Please Select' in vb 2008

2
Hello
I am trying to create a combo box that would display data from a dataset, and also a 'Please Select' as the first item. I have written the following code which derives from a combo box and it works fine in visual studio 2003 but in 2008 would not display the comboboxtext (which is 'Please select'). any one has any ideas what i have done wrong?

Expand|Select|Wrap|Line Numbers
  1. Public Class DoubleDataSourceCombo
  2.     Inherits ComboBox
  3.  
  4.     Dim myDataTable As DataTable
  5.     Public comboboxText As String
  6.     Protected Overrides Sub OnDataSourceChanged(ByVal e As System.EventArgs)
  7.         MyBase.OnDataSourceChanged(e)
  8.         Static blnDataSourceSet As Boolean = False
  9.         If blnDataSourceSet = True Then
  10.             blnDataSourceSet = False
  11.             Return
  12.         End If
  13.         myDataTable = New DataTable
  14.         If DisplayMember <> "" Then myDataTable.Columns.Add(Me.DisplayMember)
  15.         If ValueMember <> "" Then myDataTable.Columns.Add(Me.ValueMember)
  16.         Dim row As DataRow = myDataTable.NewRow
  17.         If DisplayMember <> "" Then
  18.             row.Item(Me.DisplayMember) = comboboxText
  19.         End If
  20.         If ValueMember <> "" Then
  21.             row.Item(Me.ValueMember) = DBNull.Value
  22.             'row.Item(Me.ValueMember) = -1
  23.         End If
  24.         myDataTable.Rows.Add(row)
  25.         For Each o As Object In Me.DataSource
  26.             row = myDataTable.NewRow
  27.             If DisplayMember <> "" Then
  28.                 row.Item(Me.DisplayMember) = o(Me.DisplayMember)
  29.             End If
  30.             If ValueMember <> "" Then
  31.                 row.Item(Me.ValueMember) = o(Me.ValueMember)
  32.             End If
  33.             myDataTable.Rows.Add(row)
  34.         Next
  35.         Dim ar As New ArrayList
  36.         For Each oo As Object In myDataTable.DefaultView
  37.             ar.Add(oo)
  38.         Next
  39.         blnDataSourceSet = True
  40.         Me.DataSource = myDataTable.DefaultView
  41.     End Sub
  42. End Class
'then in windows form i have the following code:
Expand|Select|Wrap|Line Numbers
  1. dim cbo as new doubledatasourcecombo
  2. cbo.comboboxtext="Please Select"
  3. cbo.displaymember="EmployeeName"
  4. cbo.valuemember="PersonnelID"
  5. cbo.datasource=dr 'which is a datarow array
any one has any ideas on this?
thanks
Jan 13 '09 #1
4 11140
raids51
59
fill the combobox from the dataset, then insert a new combobox item at the index of 0.
Jan 13 '09 #2
truezplaya
115 100+
Can't you set the combo boxes text property to please select and then populate from a dataset?
Jan 14 '09 #3
Kai12
2
thanks that should do the trick,
Jan 14 '09 #4
Try appending data to your datatable, then bind your data to your combobox

something like:

Dim newEmployeeRow As DataRow = myDataTable.NewRow()
newEmployeeRow ("EmployeeName") = "Please Select an Employee ----------"
newEmployeeRow ("PersonnelID") = "000"
myDataTable.Rows.InsertAt(newEmployeeRow, 0)

this will set "Please Select an Employee ---------" to the top of your ComboBox...
Sep 17 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Fabri | last post by:
How can I dynamically delete option from select object? I know to add: al.option = new Option('x','y'); but what about delete all or some? Thx in advance.
2
by: Pasquale | last post by:
How can I get a combo box to come up when previewing a report so that the user can select an event name and then print preview the report specific to that event? In the "On Open" event of the...
2
by: DotNetJunkies User | last post by:
hi,, im trying to work out what code is needed for the below problem about databinding a dropdown list and having actual datalist items as value "0" ie 'please select' can anyone tell me how to...
3
by: Chandeep | last post by:
Hello to all friendly helpful access experts, I have used Access many times in the past but this problem has always stumped me. I am currently developing a database and am almost certain that it...
8
by: shanmukhi | last post by:
Hi All, i am new to java script i need one requirement that is i want to display a combo box and when i select one option in it i should go to one jsf page
2
by: truthysam | last post by:
Hello, I have a combo box in C# and i can do at most: type something and the match closest will be there in combo box. But i like to do : when i type A in combo box there will be...
1
by: 14jacobf | last post by:
My Windows XP computer keeps asking me what program to open my external usb drives. I know to open them with "explorer" in the WINDOWS file on my hard-drive. How do I set it so that it will use the...
1
by: ilikebirds | last post by:
I have the current code for populating one combo box off another combo box: Private Sub Combo110_AfterUpdate() With Me! If IsNull(Me!Combo110) Then .RowSource = "" Else ...
1
by: napstar | last post by:
I have a dropdown list which has an sqldatasource but I'd like the first item on the list to be "Please Select A Title".I tried using a UNION query : SELECT MessageTable.Title FROM...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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...

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.