Access ListView item text (FMX) - firemonkey

I have a TListView and when the user clicks on the image of an item (big green dot in picture below) i want to copy the item text ("russtest.cfg") and subitem text ("My Device, 1991") to display in a ShowMessage. I can't find how to do it in C++ Builder but this link shows how in Delphi.
Below is the code i've tried in the TListView's ItemClickEx method:
TListItem* item;
item = ListView1->Items->Item[ItemIndex];
UnicodeString s;
s = item->ToString();
ShowMessage(s);
But it brings back this:
EDIT 1: Added the code i use to populate the ListView:
TListViewItem* item2Add = Form1->ListView1->Items->Add();
Form1->ListView1->BeginUpdate();
item2Add->Text = mystring3; // e.g. "russtest.cfg"
item2Add->Detail = mystring2; // e.g. "My Device, 1991"
item2Add->ImageIndex = 1; // big green dot
Form1->ListView1->EndUpdate();

Your need to typecast the TListItem* to TListViewItem*, then you can access its Text property:
TListViewItem* item = static_cast<TListViewItem*>(ListView1->Items->Item[ItemIndex]);
String s = item->Text;
ShowMessage(s);

Related

How can I change the Font of a TListBox's items?

I'm building an app with RAD Studio 11, but I can't find a way to change the item font of my TListBox.
I tried to change TListBox.Font in the Object Inspector, but when I select my TListBox called ingredientsDataBase in the Object Inspector, I can just change TListBox settings instead of TListBox.Items settings.
I add a TListBoxItem manually as follow:
Then, I can change ListBoxItem1.Font in the Object Inspector, after selecting my ListBoxItem1 (no problem).
The problem is that, when I run my program, the Font change only affects my ListBoxItem1, and I want the same Font for every item that I add to my TListBox.
UPDATE 1
After your help I tried to convert your Delphi code to C++.
__fastcall TIngredientCreator::addButtonClick(TObject *Sender){
//More code Here
//Then I ADD a new ListBoxItem to my ListBox "ingredientsDataBase"
ingredientsDataBase->Items->Add("newIngredient");
TListBoxItem *lbItem = new TListBoxItem(ingredientsDataBase);
lbItem->Parent = ingredientsDataBase;
// Remove Family and Size from the items TStyledSettings
lbItem->StyledSettings = lbItem->StyledSettings << TStyledSetting::Family << TStyledSetting::Size;
// You can now set these TextSettings as needed
lbItem->TextSettings->Font->Family = "Algerian";
lbItem->TextSettings->Font->Size = 18;
lbItem->Text = "algerian";
delete lbItem;
}
There is no syntax error, but I can't associate my new ListBoxItem, in this case the Text or Name of that new ListBoxItem called "newIngredient" (I don't know how to do it in this code), so when I run my program nothing happen to mi new Item at least.
UPDATE 2
I found a way to associate my newIngredient to TListBoxItem Object as follow:
int index = ingredientsDataBase->Items->IndexOf(newIngredient);
lbItem = ingredientsDataBase->ItemByIndex(index);
When I run the code and I add a new Ingredient, just the Text of the newIngredient is changed to "algerian", because in the first code I have this line lbItem->Text = "algerian" all good here. But Font and Size still without change.
Thanks for your answers
When you add items to the listbox, you need to clear some items from the default StyledSettings property of the new item, if you want to modify the corresponding TextSettings.
Here's an example in Delphi to do what you want:
procedure TForm5.Button2Click(Sender: TObject);
var
lbItem: TListBoxItem;
begin
lbItem := TListBoxItem.Create(ListBox1);
lbItem.Parent := ListBox1;
// Remove Family and Size from the items TStyledSettings
lbItem.StyledSettings := lbItem.StyledSettings - [TStyledSetting.Family,TStyledSetting.Size];
// You can now set these TextSettings as needed
lbItem.TextSettings.Font.Family := 'Algerian';
lbItem.TextSettings.Font.Size := 18;
lbItem.Text := 'algerian';
// In Embarcadero C++Builder you use the ">>" operator to remove members from a set, and "<<" to include them.
end;
After your help my code in a Multi-Device Application C++ Builder project result on the next code:
__fastcall TIngredientCreator::addButtonClick(TObject *Sender){
//More code Here
//Then I ADD a new ListBoxItem to my ListBox "ingredientsDataBase"
ingredientsDataBase->Items->Add("newIngredient");
int index = ingredientsDataBase->Items->IndexOf(newIngredient);
lbItem = ingredientsDataBase->ItemByIndex(index);
// Remove Family and Size from the items TStyledSettings
lbItem->StyledSettings = lbItem->StyledSettings >> TStyledSetting::Family >> TStyledSetting::Size;
// You can now set these TextSettings as needed
lbItem->TextSettings->Font->Family = "Consolas";
lbItem->TextSettings->Font->Size = 18;
delete lbItem;
}
If you are trying to do it in a Windows VCL Aplication C++ Builder Project is easier (You can change the font of the entire TListBox once):
ingredientsDataBase->Font->Size = 8.5;
ingredientsDataBase->Font->Name = "Consolas";

How to create an input box with iron python using windows.forms?

For a simple Gui in Iron python I need a simple dialog box with an input text field and OK and cancel button and return value of input text, equivalent to Visual Basic input box.
So basically, dialog pops up, you enter value, hit OK an dialog box closes and returns value to calling function.
I could not find anything in the windows forms library.
I guess you need to create a form yourself from scratch, using text box, etc..?
Is there really no input box in winforms?
If so, could anyone share how to create one with winforms and iron python?
Thanks for help!
Nils
I am new to Ironpython and GUI programming, therefore the following solution might not be elegant neither complete, but it seems to work.
Any ideas for improvement?
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Drawing import Point
from System.Windows.Forms import Button, Form, Label, TextBox, FormStartPosition, FormBorderStyle
class MyInputBoxClass(Form):
def __init__(self,message, title, defaultText):
#Creates Input Box with text Input Field
#define form
self.Text = title
self.Width = 600
self.Height = 110
self.StartPosition = FormStartPosition.CenterScreen;
self.FormBorderStyle = FormBorderStyle.FixedDialog
self.MinimizeBox = False;
self.MaximizeBox = False;
#define label
self.label = Label()
self.label.Text = message
self.label.Location = Point(10, 10)
self.label.Height = 30
self.label.Width = 250
#define text box
self.textbox = TextBox()
self.textbox.Text = defaultText
self.textbox.Location = Point(10, 40)
self.textbox.Width = 500
#define button
self.button1 = Button()
self.button1.Text = 'ok'
self.button1.Location = Point(510, 40)
self.AcceptButton = self.button1
#define dialog result
self.button1.DialogResult = DialogResult.OK;
#add controls to form
self.Controls.Add(self.label)
self.Controls.Add(self.textbox)
self.Controls.Add(self.button1)
#Todo: Handel Close Input Box Event
def MyInputBox(message, title, defaultText):
form = MyInputBoxClass(message, title, defaultText)
form.ShowDialog()
#Application.Run(form2) #this is not working, you need ShowDialog for modal form
return form.textbox.Text
def TestGui(analysis_obj):
#This function is beeing called from API
inputTextFromDialogBox = MyInputBox("Please Enter Example Text","ExampleInputBox","Its working but I'm not convinced")
print ("Input Box Return Value is '%s'"%inputTextFromDialogBox)
#ExtAPI.Log.WriteMessage("Input Box Return Value is '%s'"%inputTextFromDialogBox)

How to get selected FileView item

I have created in Visual Studio a MFC project which includes a cFileView, CDockablePane class.
As the image shows a item is selected and the menu is open. If I now klick on open the ON_COMMAND message will be called.
My problem is, how can I retrieve file name from the selected item. I have used
const MSG* pMsg = GetCurrentMessage();
HWND hWnd = HWND(pMsg->lParam);
In the pMsg pointer I can not find any item name "2020m7", only some x y coordinates.
How I can get the selected item name?
It is a CViewTree class. As in the image above you can see, the Item is selected.
HTREEITEM hItem = m_wndFileView.GetSelectedItem();
CString iText = m_wndFileView.GetItemText(hItem);
Therefore with the CViewTree pointer you can get the selected item and the item text via the HTREEITEM.
Nothing from the message is required.

Showing full text in Pin's label in xamarin

I want to display text in multiple lines in the pin's label when it is clicked, but when I have a very long text to be displayed in Address it shows me only a part of it and rest of it remains hidden eg: 'Street 12A...'.
How can I make the label to display the whole text on clicking it and if possible then in multiple lines using Xamarin.Forms.Maps.
var pin = new Pin
{
Type = PinType.Place,
Position = position,
Label = "Label Name",
Address = "some text..........."
};
map.Pins.Add(pin);
You would be to create a custom render for map on each platform to replace the standard iOS pin annotations, Android pin markers, etc...
Xamarin has a full guide for creating custom pin annotations/markers and thus you can create the UI elements you need to display your full text.
Ref: https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/map/

How to retrieve the controls inside the selected item from a listbox in WP

I'm now facing the most common problem faced my many while working with listboxes. Though I found many answers the the forum, nothing seems to work for me or else i have got it wrong. .
I have created a listbox through code. Every listbox item has a stackpanel and within it two textblocks. the stackpanel has vertical orientation.The foreground of the textblocks have been set to specific colors. When an item has been selected or clicked it moves to another page and on the close of the new page it returns to the old page.
My problem is that, when a listbox item has been clicked, it does not show the selection color which is by default the phones accent color before moving to the next page. Is it because the color of the textblocks have already set while creating the listbox?
So i tried to set it the foreground of the selected item through the SelectionChanged() like this
ListBoxItem selItem = (ListBoxItem)(listboxNotes.ItemContainerGenerator.ContainerFromIndex(listboxNotes.SelectedIndex));
selItem .Foreground = (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"];
But this does not work, and i assume its cuz there is a stackpanel inside the item.
How exactly this needs to be done? Do i need to retrieve the textblocks inside the stackpanel and set the foreground?? I have not used binding here. Visual Tree Helper???
Thanks
Alfah
In general, the selected color doesn't change on lists where you're navigating.
From my experience with android, there's no 'selector' background on WP7. If you're looking for a cool UI effect that shows some action is happening, the TiltEffect is definitely recommended, and very easy to implement.
http://www.windowsphonegeek.com/articles/Silverlight-for-WP7-Toolkit-TiltEffect-in-depth
However - if you're creating an app that doesn't have immediate navigation, it is possible that you might want a 'selected' cell color / etc. I've attached an image:
https://skydrive.live.com/redir.aspx?cid=ef08824b672fb5d8&resid=EF08824B672FB5D8!366&parid=EF08824B672FB5D8!343
If you note here, the buttons are related to the selected item on the list - I.e. the user can perform 4 different actions based on the selected item, (but they must select an item first!).
internal void SelectionChanged()
{
var item = (((ListBoxItem) _view.servers.SelectedItem).Content) as StackPanel;
if (item != null)
{
for (int i = 0; i < _view.servers.Items.Count; i++)
{
var val = (((ListBoxItem) _view.servers.Items[i]).Content) as StackPanel;
var tb = val.Children[0] as TextBlock;
var tb2 = val.Children[1] as TextBlock;
if (i == _view.servers.SelectedIndex)
{
tb.Foreground = tb2.Foreground = (SolidColorBrush) App.Current.Resources["PhoneAccentBrush"];
}
else
{
tb.Foreground = tb2.Foreground = (SolidColorBrush) //regular color here, b/c all these should no longer be selected
}
}
}
}
The ListItemContainer will have it's Foreground changed automatically. To inherit this, simply don't specify a colour (or style) on your TextBlock.

Resources