DevExpress Add items to ComboBox at run time - vb.net

I've recently started using the DevExpress Comboboxes and other UI components. But I'm struggling to add items to the ComboBoxes during rune-time. The default Visual Basics's ComboBox worked simply by using the Items.Add code... But DevExpresses seam much more complicated, I've spent the last hour trying to work out how to add an item to the Combobox during run-time. And now this is my final option.
Has anyone got an idea on how this could be done? To be a little clearer, I'm trying something like this:
If combobox1.SelectectItem = "Item1" Then
Combobox2.items.add("Added Item String")
end if
just using syntax the DevExpress classes will 'understand'.

All DevExpress editors have the SomeEditor.Properties property which contains settings specific to the editors. So, you can get Items collection from comboBox.Properties.Items property:
If combobox1.SelectectItem.ToString = "Item1" Then
Combobox2.Properties.Items.Add("Added Item String")
End If

Related

Strange behaviour while trying to add values in a DataGridView

I'm trying to add values, located in a ListView, inside a DataGridView. The strange behaviour is that VS skips the adding process from the Listview to the DataGridView, so the DGV remains empty. I said that the compiler skips this process because the commands written after the code I'm reporting are done. I've also tried to replicate this section of the software on a new project and it works properly. In the listbox there are only numbers and I verified, through a debug windows, that the Listview is not empty. Here is the code I'm using:
For Each item As ListViewItem In Form25.ListView1.Items
With item
Dim elemCorrente() As String = { .Text, .SubItems(1).Text}
Form2.DataGridView2.Rows.Add(elemCorrente)
End With
Next
Where do am I doing wrong? Thanks all are gonna help me. Best regards

ListView Not Displaying Added Text

Background:
Hello everyone, I'm not new to visual basic or programming. I just find it the fastest to make a GUI in visual basic for various programs; however, I'm having a recent issue.
I have a form with a ListView control that I populate using a textbox and a button.
the code I use for the button is:
Code:
listview1.items.add(textbox2.text)
Pretty simple code that has always worked. I changed a few properties on my ListView as well, and I will list them. I just don't know what is going on.Here's a list of the properties changed (everything else is default):
Properties:
BackColor = DarkGray
BorderStyle = FixedSingle
HeaderStyle = None
MultiSelect = False
View = Details
All properties were changed via the properties tab and not through code. I want to be able to add text to the control. I'm not adding any subitems either. I'm just confused because this code has always worked, and I've never had this issue. I'm also using Visual Basic 2010 Express Edition if that helps.
If the added item in ListView is not displaying then check the ListView.View property. if this property has set to Detail view then Columns must be added in that listView control otherwise added item will not display.
Make sure item is added correctly.
Dim item As ListViewItem = listView1.Items.Add("Item Text") ' This text will be displayed in first column. The column index will be 0
' Further values will be added in SubItem
item.SubItems.Add("Sub Item1")
item.SubItems.Add("Sub Item2")
item.SubItems.Add("Sub Item3")

vb.net listview equivalent to VB6 listindex

I am trying to get the following VB6 listindex to work within my vb.net code:
setTheR CStr(payReq.ItemData(payReq.ListIndex))
But if i copy and paste that into VB.net it wont accept it.
This is what VB.net did with the converting of the VB6 to .net code:
strContract = payReq.Items.Item(payReq.FocusedItem.Index).Text
However, checking that value it returns the name instead of the index. While the VB6 code returns the value of 2311 (which is what it needs to return)
When i add items to the listview i do this:
Item = payReq.Items.Add(rsPayRequests.Fields("userid").Value)
Item.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, VB6.Format(rsPayRequests.Fields("reqdatetime").Value, "mm/dd/yyyy")))
But i noticed it does this as well:
payReq.Items.Add(New VB6.ListBoxItem(Item, rsPayRequests.Fields("requestNum").Value))
But that does not work with my listview in .net since that above is a listbox and not a listview. Is there an equivalent in .net for the listbox to have a custom index?
Any help would be great!
David
Try strContract = lstPayRequest.FocusedItem.Index
The way you are using it is returning the item at that index
Edit:
To answer your question you can add subitems to a listviewitem or you could use the tag property of the ListViewItem for your custom index.
Dim lv As New ListViewItem
lv.Text = "Item1"
lv.Tag = 1001
lv.SubItems.Add("SubItem1")
lv.SubItems.Add("SubItem2")
lstPayRequests.Items.Add(lv)
Assuming I've read this right, you're doing what many a VB6 programmer did. You're storing a relevant value in the ItemData field that isn't the index but is related to the item. Very common practice in VB6.
Unfortunately, that practice is not directly supported in VB.NET. The VB.NET list box does not have the concept of ItemData thus a direct conversion of the VB6 code is not possible. The only solution I've encountered for this is to create a class based on the ListViewItem class. It could have a display name and an item data property. Then when you add items to the list, you create your custom item class, populate the properties and add that instance to the list. Then you can retrieve the item data value by casting the selected item into your custom item class.
It's a lot of work to replicate built-in VB6 functionality but it's the only option I've seen. Hopefully someone has a better answer to this question and I'll learn too.

CheckedListBox VB.Net MultiExtended SelectionMode

I have a CheckedListBox with a few items and I want to allow user to select more than one using arrows keys or mouse clicks combined with shift and ctrl keys so I set SelectionMode property to MultiExtended.
In design time it is not possible I get an error:
value property is not valid.
and if I set it in runtime by doing:
clbEmployees.SelectionMode = SelectionMode.MultiSimple
I get an error too:
CheckedListBox is not compatible with multiple selection.
How could I do this?
It's not supported for the CheckedListBox.
However, I'm fairly sure that you could mimic that functionality in a ListView. Just look at the CheckBoxes and MultiSelect properties of the Listview. As far as I can tell from the documenation those are compatible.
This might be too late, but I just put my solution here; Works perfect for me:
1- Just leave the CheckedListBox Selection mode as "ONE' in property sheet.
2- in your code, loop thru the checked item in your checked Box using the checked item property as following:
For each XX as 'DataTpe' in CheckedListBox.CheckedItems
'Here you assign each checked item to wherever you want to direct to'
Next

Changing styling of DataGridViewComboBoxCell from DropDownList to DropDown?

(This question is narrower in scope than this question I asked earlier.)
Say I have a DataGridViewComboBoxColumn, and want to switch the style of the ComboBox control between DropDownList and DropDown (mainly for the text field editing capability). I'd like to do this on a row-by-row basis (at the DataGridViewComboBoxCell level).
How would I do that programatically?
Or maybe a different way of asking: How do I access the ComboBox control given an object of type DataGridViewComboBoxCell?
(I'm in VB 2005.)
Thanks as always.
Not sure if you still need an answer, but i have a question that covers similar ground: Detect which column is showing an editing control in a datagridview
i use something like this line to get the combobox out of the DataGridView (DGV) in my DataGridView's CellValidating event:
Dim comboBox As DataGridViewComboBoxCell = DGV.Item(e.ColumnIndex, e.RowIndex)
later i use this line to get change the DropDownList ComboBoxCell to a DropDown:
cb.DropDownStyle = ComboBoxStyle.DropDown
For mine to work i had to make sure the 'cb' was of the ComboBox type, i dont remember if i was able to get it working well if the combobox was of the DataGridViewComboBoxCell type.