Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Elegant Ribbon Tech Support » ComboBox Editable Issue Collapse All
Subject Author Date
Paddy Jan 10, 2011 - 5:13 AM

Hi,

I have many ComboBoxes on the form.  All are Editable = False except for two.  I have specified this within the properties window; however, when I go to run the form in run-time... The ones that should be editable aren’t.  Any suggestions?  Thanks.

Technical Support Jan 10, 2011 - 10:23 AM

Please make sure that the ComboBox control on the second form has been bound to the data source at the moment you are trying to change its SelectedItem property.

Paddy Jan 18, 2011 - 10:40 AM

I have been trying to get this work for weeks now and it still won’t default on the second form!!!!

Paddy Jan 18, 2011 - 10:51 AM

I have tried everything I can think of and it’s not working.  If I can’t get a simple thing to work then I am trashing that form altogether!


 


This is the code I am using to populate the form and then I am trying to get the defaulting done from the SAME code. It isn’t doing anything!

<CLSCompliant(True)> Public Sub PopulateDropDownListFromDB(ByVal cboName As Elegant.Ui.ComboBox, _
ByVal TableName As String, ByVal ColumnName As String, _
ByVal UseAutoComplete As Boolean, _
ByVal UseSQLDistinct As Boolean)

Using SetDatabaseConnection As New SqlConnection(GetDatabaseConnectionString)
’Specify an SQL query.
Dim sSQL As String = Nothing

If UseSQLDistinct Then
’NOTES: frmReportSelection has some dupes from the DB, use DISTINCT in the SQL.
sSQL = "SELECT DISTINCT " & ColumnName & " FROM " & TableName
Else
sSQL = "SELECT " & ColumnName & " FROM " & TableName
End If

’Assign the SQL query and database connection to the DataAdapter.
Dim MyDataAdapter As New SqlDataAdapter(sSQL, SetDatabaseConnection)

’Create a new instance of a DataSet.
Dim MyDataSet As New DataSet
MyDataSet.Locale = CurrentCulture

Try
’Clear the DataSet of any previously obtained database information.
MyDataSet.Clear()
’Refill the DataAdapter with new information obtained from the database.
MyDataAdapter.Fill(MyDataSet, TableName)

With cboName
’First check to see if any records. If no records, add a default item.
Dim MyDataTable As DataTable = New DataTable
MyDataTable.Locale = CurrentCulture
MyDataTable = MyDataSet.Tables(TableName)

’Fill the ComboBox.
’Assign the database table to the DataSource property.
.DataSource = MyDataSet.Tables(TableName)
’Assign the database column name to the DisplayMember and ValueMember properties.
.DisplayMember = ColumnName
.ValueMember = ColumnName

If UseAutoComplete = True Then
.AutoCompleteMode = AutoCompleteMode.SuggestAppend
.AutoCompleteSource = AutoCompleteSource.ListItems
End If

’Take the value from cboPartnerName on frmWorkLogEntryStart and default it on frmWorkLogEntry.
If .Name Is "cboPartnername" Then
With frmWorkLogEntryStart
frmWorkLogEntry.cboPartnerName.SelectedItem = .cboPartnerName.Items(.cboPartnerName.FindStringExact(.cboPartnerName.Text, 0))
End With
End If

If MyDataTable.Rows.Count > 0 Then ’Has records.
If .Editable = False _
And UseAutoComplete = False Then
’Specify a default selection in the ComboBox.
.SelectedIndex = 0
End If
Else
.DataSource = Nothing
.Items.Add("[Please Add An Item]")
.SelectedIndex = 0
End If
End With
Catch ex As SqlException
’Show the end user a message if an error is generated.
MessageBox.Show("There was an error retrieving data from table name " & TableName & " for the column " & ColumnName & "." & vbNewLine & vbNewLine & _
"We are going to prepopulate the dropdown menu with a default value; therefore, you can disregard the error." & vbNewLine & vbNewLine & _
"We highly suggest that you click on the plus sign next to the dropdown menu to add some options of your own." & vbNewLine & vbNewLine & _
"The reason why you got this error in the first place is:" & vbNewLine & _
"No data items in the database " & TableName & " to pull." & vbNewLine & vbNewLine & _
"The exception error is:" & vbNewLine & _
ex.Message, _
"Database Information Retrieval Issues.", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.DefaultDesktopOnly, _
False)

’If no rows are returned to populate the ComboBox, this will return an error, prepopulate with [Please Add An Item]
With cboName
.DataSource = Nothing
.Items.Add("[Please Add An Item]")
.SelectedIndex = 0
End With
End Try
End Using ’SetDatabaseConnection.
End Sub

Paddy Jan 18, 2011 - 11:12 AM

I even tried the following and no change. Doesn’t make any sense!



If MyDataTable.Rows.Count > 0 Then ’Has records.
If .Editable = False _
And UseAutoComplete = False Then
’Specify a default selection in the ComboBox.
.SelectedIndex = 0
ElseIf bNewCallSingle Then
If .Editable = False _
And UseAutoComplete = False Then
If .Name = "cboPartnerName" Then
’Take the selected value from frmWorkLogEntryStart and make it default on frmWorkLogEntry.
With frmWorkLogEntryStart
frmWorkLogEntry.cboPartnerName.SelectedItem = .cboPartnerName.Items(.cboPartnerName.FindStringExact(.cboPartnerName.Text, 0))
End With
Else
’Specify a default selection in the ComboBox.
.SelectedIndex = 0
End If
End If
End If
Else
.DataSource = Nothing
.Items.Add("[Please Add An Item]")
.SelectedIndex = 0
End If

Technical Support Jan 19, 2011 - 2:52 AM

Could you send us a test project that illustrates the issue? We will check what’s wrong and send it back to you as soon as possible. That would allow us to help you more efficiently Thank you for understanding.

Technical Support Jan 10, 2011 - 6:36 AM

It sounds really strange. We created a simple project and were unable to reproduce the issue. Please send us a test project so we can check it on our site.

Paddy Jan 10, 2011 - 8:50 AM

OK, I went through my code just incase I had missed something and this is what I found.  The two ComboBoxes called cboClientName and cboDispatcherOrConsultantName are not bound to any datasource.  They are going to be but not yet.  However, they also show a default value of [Please Add An Item] when it should be blank and editable.


It looks like it could be this code but I thought I had allowed for that because I explicitly specified names of the controls not to touch but seems they are being touched anyway.  I am going to have to play around with the code a little.


My current code is:


ElseIf TypeOf GrandChildControl Is Elegant.Ui.ComboBox Then
’Make sure the controls FontStyle within the GroupBox is regular FontStyle
’because it’ll automatically take on the FontStyle of its container control.
’The container control being the GroupBox. (FontStyle.Bold).
With DirectCast(GrandChildControl, Elegant.Ui.ComboBox)
’If there is no error and there are no items in the list, add one.
If .Items.Count = 0 Then
Try
If Not GrandChildControl.Name Is "cboDispatcherOrConsultantName" _
Or Not GrandChildControl.Name Is "cboClientName" Then
.Items.Add("[Please Add An Item]")
.SelectedIndex = 0
.Editable = False
Else
.Editable = True
End If
Catch ex As ArgumentException
MessageBox.Show(ex.Message, _
"Argument Exception", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.DefaultDesktopOnly, False)
End Try
End If

Paddy Jan 10, 2011 - 8:56 AM

OK, I got that sorted.  It was that code.  I just switched it and only those two are editable whereas the others aren’t.



Code:


With DirectCast(GrandChildControl, Elegant.Ui.ComboBox)
’If there is no error and there are no items in the list, add one.
If .Items.Count = 0 Then
Try
If GrandChildControl.Name Is "cboDispatcherOrConsultantName" _
Or GrandChildControl.Name Is "cboClientName" Then
.Editable = True
Else
.Items.Add("[Please Add An Item]")
.SelectedIndex = 0
.Editable = False
End If
Catch ex As ArgumentException
MessageBox.Show(ex.Message, _
"Argument Exception", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.DefaultDesktopOnly, False)
End Try
End If

.Font = New Font(.Font, FontStyle.Regular)
’Set a default width.
.Size = New Size(ComboBoxTextBoxSize)
End With

Technical Support Jan 10, 2011 - 10:23 AM

We are glad that you’ve found the solution.

Paddy Jan 10, 2011 - 9:25 AM

One last thing about ComboBoxes before I go.  I have two ComboBoxes with the same name that reside on different forms.  The name of the ComboBox is cboPartnerName.


These ComboBoxes are bound to a database to pull information from it.  I am able to get it working; however, when I get my initial screen, I select an item from it, click Start and then my next form comes up.  I am looking to default the value selected on the previous screen in that ComboBox.


I have tried the following and it isn’t changing the value.


With frmWorkLogEntryStart

’TODO

’frmWorkLogEntryStart.cboPartnerName = frmWorkLogEntry.cboPartnerName

cboPartnerName.SelectedItem = .cboPartnerName.Items(.cboPartnerName.FindStringExact(.cboPartnerName.Text))

End With


Any ideas on what might be going on?  I can’t even select the SelectedIndex because it errors out with a NullException.