What is the "object type" of the .List property of a combobox in vba? I am having quite a struggle in accessing the items when I treat it like a an Array of strings.
Let's say I want to go through the list and check if any of the items match a certain string, how would I go about that?
Levraininjaneer, I think I might have some help for you...
I've made a windows form with a combobox, a button, and a listbox... The combobox has some items in it, like Item 1 to Item 3, "ABC", "DEF", "GHI"...
Now, you say you want to access the items in your list? Well, try this out...
string[] array = new string[comboBox1.Items.Count];
int itemCount = comboBox1.Items.Count;
for (int i = 0; i < itemCount; i++)
{
array[i] = (string)comboBox1.Items[i];
string item = array[i].ToString();
this.listBox1.Items.Add(item);
}
MessageBox.Show(array[1]);
MessageBox.Show(array[4]);
And it will do this:
And the message boxes at the bottom of the code will display "Item 2" & "DEF"
If you want to "save" an instance of an item in the list box, you can also do it like this:
string arrayItem = array[3].ToString();
MessageBox.Show(arrayItem);
This will display a message box saying "ABC" as the index (number in [square] brackets, it starts at 0 generally... So if you put array [1] . it's not the 1st item, it's actually the 2nd item... If you wanted to get the last item, and if there's 6 items, it would be:
array[5];
And also, if you wanted to check if an object contains a certain string, you can always use the .Contains method of a string
.Contains("Item")
Hope this helps :)
Win10Pro(x64)
Visual Studio 2015 Community
C#
WindowsForm project
Related
I'm trying to add the option to my users that, on a List Validator, to allow select any of the options or a blank option. Spreadjs has the IgnoreBlanks setting, which I use, so when the user uses the delete key or the backspace and deletes the cell it validates correctly.
However, I would love to use the same functionality as in Excel, which allows blank options in the list validator, in part of the list.
I've tried to target the <select> element that holds the list and programmatically add the empty element, however, it crashes after the user selects the empty option.
I've also tried to add different escaped characters to the list. If I select a character that represents an empty string or a tab, it won't add a new option to the list. If I use any strange character, or even the null character \0 you get a new option to select, but the content is that typical rectangle you see when your font doesn't have the character you're trying to display.
I've also tested using a regular ListValidator like in the example pages, not our custom functionality and doesn't work either.
https://www.grapecity.com/demos/spread/JS/TutorialSample/#/demos/basicDataValidator
I have also tried creating a FormulaListValidator, and if my range has empty cells I could then get an empty option on my list, however, because the range may have duplicates, I get duplicated options.
After researching a little bit I found a workaround in a different language which I adapted to Typescript (Angular 6)
export const getListValidatorFromArray = (spread: GC.Spread.Sheets.Workbook, data: any[]) => {
// saving validation list values in a hidden sheet
spread.addSheet(spread.getSheetCount());
const sheet = spread.getSheet(spread.getSheetCount() - 1);
sheet.visible(false);
for (let i = 0; i < data.length; i++) {
sheet.setValue(i, 0, data[i]);
}
// create validator based on the values
const dv = GC.Spread.Sheets.DataValidation.createFormulaListValidator(
'=' + sheet.name() + '!$A$1:' + sheet.name() + '!$A$' + data.length
);
return dv;
};
Note: This creates an extra sheet for each validator you create. Makes sure you reuse them as much as possible (i.e. assigning it to a variable when it's created, and reusing the variable for other columns/rows that use the same one).
The problem im getting is if type something in my entry box it first fills index 1 and 2 of the listbox before finally typing into the 3rd index.
def country_get(event):
listbox.delete(3)
listbox.insert(3, country_label.cget('text') + event.widget.get() + '\n')
title_text=StringVar()
entry_country=Entry(master, bg="wheat3", fg="dark slate gray", textvariable=title_text)
entry_country.bind('<KeyRelease>', country_get)
entry_country.grid(row=4, column=1)
I want to be able to type at any index of the listbox whether it be the 3rd or 5th, without having anything at the previous index's.
You can't do what you want. The listbox isn't designed to have empty rows. If you want empty rows, you will need to insert empty strings.
Depending on how many entries I'm using or need, i just insert empty strings like so:
listbox.insert(0, "")
listbox.insert(1, "")
listbox.insert(2, "")
listbox.insert(3, "")
listbox.insert(4, "")
It appears that the listbox is empty when it fact it is just filled with empty strings. There are most likely other ways to get around this, but for what I need my program to do, this is what worked for me.
Can someone help with my code searching for a partial match. I seem to be stuck here.
I would like type only the first few letters in a combo-box, hit enter, and store whatever I have typed as a variable. Then I want to check my variable against my list for the closest name that matches what I have typed. That becomes the new variable. How do I do this?
#singleInstance, Force
list =
(
Phone Numbers
Important People
Modification
Traffic Data
Tasks
Tracker
)
Gui, +alwaysontop
Gui +Delimiter`n
Gui, Add, ComboBox, vMyVar w200 h110 CHOOSE1 sort, % LIST
Gui, Add, Button, gGO Default x+5 w60 h20 , GO
Gui, show, y200, What do you want now?!
return
; Type first couple letters in box hit enter
GO:
Gui, Submit, nohide
Loop, parse, List, `n
{
; Search LIST for nearest match
;First partial match found
; MyVar := "A_loopfield"
MsgBox % InStr(A_loopfield, DoThis)
}
if MyVar = Phone Numbers
; Msgbox or Function ETC..
Try
#singleInstance, Force
list =
(
Phone Numbers
Important People
Modification
Traffic Data
Tasks
Tracker
)
Gui, +alwaysontop
Gui +Delimiter`n
Gui, Add, ComboBox, vMyVar w200 h110 CHOOSE1 sort, % LIST
Gui, Add, Button, gGO Default x+5 w60 h20 , GO
Gui, show, y200, What do you want now?!
return
; Type first couple letters in box hit enter
GO:
Gui, Submit, nohide
GuiControlGet, text_typed,, ComboBox1
StringLen, length, text_typed ; retrieves the count of how many characters are in the text typed
Loop, parse, List, `n
{
If (SubStr(A_LoopField, 1, length) = text_typed)
{
GuiControl, Choose, MyVar, %A_LoopField%
If (A_LoopField = "Phone Numbers")
MsgBox, Item 1
; ...
If (A_LoopField = "Traffic Data")
MsgBox, Item 6
break
}
}
return
I need to delete a qlistwidget item by text content
I tried:
QString mstring = "Programmer II";
QList<QListWidgetItem *> items = ui->listJobs->findItems(mstring, Qt::MatchExactly);
if (items.size() > 0)
ui->listJobs->takeItem( ui->listJobs->currentRow() );
...and various permutations, but I'm missing something. The code above compiles, but does not delete the item from the qlistwidget.
The code doesn't indicate what the value of currentRow is, but findItems doesn't set it, so it's unlikely to correlate with the value you're trying to remove. I don't see any way to use the results of findItems and get the row(s) you want to remove. I think you have to loop through the contents, compare the text of each item, and then remove the ones that match. You'll probably want to do the loop in reverse order; otherwise, once you've removed an item, the loop counter will no longer match the list item's row numbers.
I have a GTK application that has a window with a treeview and a button. When the button is clicked I need to get the data from the first (and only) column of the selected row in the treeview.
This is the class for the columns:
class ModelColumns:
public Gtk::TreeModel::ColumnRecord{
public:
ModelColumns(){ add(m_port_name); }
Gtk::TreeModelColumn<Glib::ustring> m_port_name;
};
This is like in the example here but with only one column: http://www.lugod.org/presentations/gtkmm/treeview.html
This is the button click signal handler at the moment:
tvPorts is the treeview widget
tvPortsList is the listStore for the treeview
static
void on_btnPortSelectOK_clicked (){
Glib::RefPtr<Gtk::TreeSelection> selection = tvPorts->get_selection();
Gtk::TreeModel::iterator selectedRow = selection->get_selected();
//Now what?
//Need to get data from selected row to display it.
}
I have searched the documentation and many examples to try and find out what to do next but can't find any examples for gtkmm, I can only find examples for c or python implementations.
As far as I can tell, I need to get a TreeRow object from my iterator (selectedRow) how do I do this?
Thanks.
Update:
I am now using this code and it almost works.
The only problem is that it prints the previous selection.
The first time I select something and then press the button it prints only a new line. The second time it prints what was selected the first time, the third prints the second, etc.
Glib::RefPtr<Gtk::TreeSelection> selection = tvPorts->get_selection();
Gtk::TreeModel::iterator selectedRow = selection->get_selected();
Gtk::TreeModel::Row row = *selectedRow;
Glib::ustring port = row.get_value(m_Columns.m_port_name);
printf("\nselected port: %s", port.data());
This seems odd.
(m_Columns is an instance of the ModelColumns class)
Update 2:
Fixed the problem by adding fflush(stdout);
It all works now, thanks.
The docs say to simply dereference the iter to get the TreeRow:
Gtk::TreeModel::Row row = *iter; // 'iter' being your 'selectedRow'
std::cout<<row[0];