473,398 Members | 2,403 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.

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 11143
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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.