I have a List Control in MFC.
With that code:
m_Eintrag3 = m_List.InsertItem(0, _T ("Schaller"));
m_List.SetItemText (m_Eintrag3, 1, _T ("Benedikt"));
m_List.SetItemText (m_Eintrag3, 2, _T ("05.08.1996"));
I can insert an Item and Text in my List Control.
With that code:
if ((m_List.FindItem(&Finde)) != -1)
I can find an Item. But I want to find ItemText. Not just the Item.
Is there any solution? FindItemText doesnt exist.
You have to write your own loop, that checks the Subitems too... FindItem only works on the Item entry. Never on subitems.
Related
I currently have a combobox which displays a list of numbers which are retrieved elsewhere and stored into the variable "test". Every time another number is set for "test", that number will be added into the combobox list.
Is there a way where I can use a CEdit text box instead of a CComboBox to display my numbers?
This is how I have coded the combobox.
CComboBox *pCombobox = (CComboBox *) (GetDlgItem(IDC_ComboBox));
strNumber.Format(_T("%d"),test);
pCombobox->AddString(strNumber);
Any help would be appreciated. Thank you.
Presuming you have an appropriate edit control placed on your dialog with ID IDC_Edit for example, then get the existing string, append the new value to it, replace with new string.
CString text;
GetDlgItemText(IDC_Text, text);
if (text.IsEmpty())
text.Format(_T("%d"), test);
else
text.AppendFormat(_T(",%d"), test);
SetDlgItemText(IDC_Text, text);
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.
If I want to change the focus item in the ListView control I do the following:
BOOL setListFocusItem(CListCtrl* pList, int nIndex)
{
return !!pList->SetItemState(nInd, LVIS_FOCUSED, LVIS_FOCUSED);
}
Is this the way you do it?
Because the focus itself changes but there's one issue that this creates. For instance, if the list had 100 items and the focus was on item 1. If I then call my method as such setListFocusItem(99); the focus changes to item 99, but then if I shift-click on item 90, I would expect the list to have items 90 through 99 to be selected. But instead the list selects items 1 through 90. So obviously my setListFocusItem() method does not change the shift-click "first" location. So question is how to make it do it?
Short answer : use the LVM_SETSELECTIONMARK message.
(In MFC-ese, CListCtrl::SetSelectionMark).
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
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];