Finish control loading - compact-framework

I've a method which fill a combobox. (compact framework 3.5)
lstNiveaux.BeginUpdate();
lstNiveaux.Items.Clear();
for (int i = 0; i < list.Count; i++)
{
var item = new ListViewItem(list[i].value);
lstNiveaux.Items.Add(item);
}
lstNiveaux.EndUpdate();
I want to do :
lstNiveaux.Items[10].Selected = true;
lstNiveaux.EnsureVisible(10);
When I write that piece of code at the end of the previous method, it won't work but ... if I put a button with a click event, and the piece of code inside, it will work.
I tryied Application.DoEvents, Thread.Sleep and other stuff but no work. Does someone has a solution ?
regards

Related

I'm looking for a solution for a loop with a array of images

so what i'm trying to do is to change the images that's stored in a array that contains 16 imgs, it's basically a animation for when you play a game (press forward character moves[moving imgs], release button character stops[stoped img]). The thing is that after the array reaches it's length max and the key is still being pressed it needs to reset the array to 15 (so this loop will give the illusion of the constant movement), but i think i'm not finding the right synthax or something.
Thanks in advance.
PImage p1;
PImage[] zeroArray = new PImage [16];
void setup() {
size(600,600);
for(int i = 0; i < zeroArray.length; i++){
zeroArray[i] = loadImage (i + ".png");
}
}
void draw() {
background(255);
imageMode(CENTER);
if(keyPressed) {
i++;
} else if (i > zeroArray.length) {
zeroArray[] = zeroArray[15]; // <--this ain't right, how should i declare this??
}
image(zeroArray[i], 300, 300, 800, 800);
}
I think you're mixing a few ideas into one if statement. Let's take a look at this section of your code:
if(keyPressed){
i++;
}
else if (i > zeroArray.length){
zeroArray[] = zeroArray[15];
}
Run through this line-by-line and really think about what it's doing. If a key is pressed, it increments the i variable. If a key is not pressed, then it checks whether i is greater than the length of the zeroArray array variable. If it is, it attempts to reset the array, which is not valid syntax.
Take a step back and think about what you're trying to do. Forget about code for a second. Write down exactly what you're trying to do, in English. My guess is you're trying to do something like this:
Change the image being drawn whenever the key is pressed.
If we reach the end of the images, then start over at the first image.
When you have something like that written out, that's an algorithm that you can start thinking about implementing with code. Break your problem down into smaller steps and take those steps on one at a time.
For example, step 1 is to change the image whenver the key is pressed. You basically have that already:
if(keyPressed){
i++;
}
Then, step 1 is to reset the i variable whenever it reaches the end of the array. You might do that using an if statement like this:
if(i >= zeroArray.length){
i = 0;
}
Putting it all together, it would look like this:
if(keyPressed){
i++;
if(i >= zeroArray.length){
i = 0;
}
}
Now this code checks if a key is being pressed, and if so it increments the i variable. It then checks whether the i variable has gone past the end of the array, and if so it reset it back to the beginning.
If that's not exactly what you're looking for, then the process of solving your problem is still the same: you need to write down, in English, exactly what you're trying to do. You need to do that before you start hammering away at the code.
Are you sure you want to reset the array to 15? That's the last element. However, in general, the solution would be to change the line:
zeroArray[] = zeroArray[15];} // <--this ain't right, how should i declare this??
to
i = 15; //Just change the index pointer to 15 (or whichever frame you want to reset to)
Thank you all for the answers, they really gave me some light.
To Kevin Workman.
Writing down the path that i intended to take really helped out, your thinking was almost on point. Using your method i came up with this
1)Change character sprites if key is being pressed
2) Reset movement to a certain point in case it exceeded the animation sprites, and the key is still being pressed
3)Set to fist sprite if the key is released or not being pressed at all
To Sahil Jain
You were right about changing the index to [15], it didn't work so well
Here is the revised code:
PImage p1;
PImage[] zeroArray = new PImage [16];
void setup(){
size(600,600);
for(int i = 0; i < zeroArray.length; i++){
zeroArray[i] = loadImage (i + ".png");
}
}
void draw(){
background(255);
imageMode(CENTER);
if (keyCode == RIGHT){
if(keyPressed){
i++;
} else {
i = 0;
}
if (i >= zeroArray.length){
i = 4;}
image(zeroArray[i], 300, 300, 800, 800);
}
}
Have you tried switching your else if to your main argument in the last If...Then statement? Also, don't forget to reset your variable i to 0 so it resets too and doesn't continue to always try to reset and end up in an infinite loop of sorts :)
As it is in your code in the question, it does the increment first and will never follow through to read into the second choice (the one you want it to do).

How to give an dynamicly loaded TreeViewItem an EventHandler?

at the moment i programm a database based Chat System.
The friendlist of every User gets loadet in a TreeView after the login.
means:
After the login I request the names of the useres friends by the following Funktion,
String namesSt[] = get.getUserFriendNameByUserID(currentUserID);
To use the given Names to load them as TreeItem into my Friendlist / TreeRootItem "rootItem"
for (int counter = 0; counter < namesSt.length; counter++) {
System.out.println(namesSt[counter]);
TreeItem<String> item = new TreeItem<String> (namesSt[counter]);
item.addEventHandler(MouseEvent.MOUSE_CLICKED,handler);
rootItem.getChildren().add(item);
}
When I now add my rootItem, I see the Names in the TreeView.
But if I click on a name, the given MouseEventHandler doesn´t get called.
Further I just want to request the text of the Element which trigger the MouseEvent, so that i can submit these name to a spezial funktion.
How can i realice such an MouseEvent?
How is it possible to call it from the dynamicly created TreeItem?
Thank you for any help :)
cheerse
Tobi
TreeItems represent the data, not the UI component. So they don't generate mouse events. You need to register the mouse listener on the TreeCell. To do this, set a cell factory on the TreeView. The cell factory is a function that creates TreeCells as they are needed. Thus this will work for dynamically added tree items too.
You will need something like this:
TreeView<String> treeView ;
// ...
treeView.setCellFactory( tv -> {
TreeCell<String> cell = new TreeCell<>();
cell.textProperty().bind(cell.itemProperty());
cell.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
if (! cell.isEmpty()) {
String value = cell.getItem();
TreeItem<String> treeItem = cell.getTreeItem(); // if needed
// process ...
}
});
return cell ;
}

Livecycle: Referencing objects in repeated subforms

I have a form that I want to lock for presentation once it is filled out. I know how to make this happen with a button to render the text fields read-only. Now I have a form that involves repeated subforms (added as needed). How can I script a single button so it will work for the objects in all the subforms?
The subforms are iterations of "ItemGroup". I need to make "ItemGroup.Item" and "ItemGroup.ItemRx" read-only, and "ItemGroup.ItemHeader.Button" invisible.
I'm at home, hence untested. Let me know if you bump into trouble.
var sfSom = "<path/somExpression to subform containing ItemGroups>"; var nn, n = xfa.resolveNode(sfSom).nodes;
for (var i = 0; i < n.length; i++) {
nn = n.item(i);
if (nn.name == "ItemGroup" && nn.className == "subform") {
/* change stuff here. Decide if Item and ItemRx should be read-only, calculate or protected. For now, we'll settle for hiding the button: */
nn.ItemHeader.Button.presence = "hidden";
}
}

Cutom Keyboard On windows CE

I have coded a custom keyboard on CF 35. , Windows CE 6.0 .
It is created and added to form on BaseForm and all forms inherit from this one.
So my problem is : custom keyboard takes 1-2 second to be created and located on every form load.
how can i get solve this?
Here is the Constructor of Keyboard
public KeyBoard()
{
InitializeComponent();
panelNumeric.SendToBack();
panelNumeric.Visible = false;
this.Visible = false;
//Click event
for (int i = 0; i < this.Controls.Count; i++)
this.Controls[i].Click += new EventHandler(ButtonClick);
panelNumeric.Click -= ButtonClick;
for (int i = 0; i < panelNumeric.Controls.Count; i++)
panelNumeric.Controls[i].Click += new EventHandler(ButtonClick);
//Caps Lock
btnListForCaps = new List<Control>(){btnQ,btnW,btnE,btnR,btnT,btnY,btnU,btnI,btnO,btnP,btnP,btnTRG,btnTRU,btnA,btnS,btnD,btnF,btnG,btnH,btnJ,btnK,btnL,btnTRS,btnTRI,btnZ,btnX,btnC,btnV,btnB,btnN,btnM,btnTRO,btnTRC};ButtonClick(btnShift, null);
}
i found the solution.
i added a new form and locate keyboard buttons on it.
Create keyboard form on application load and declare it as a static global variable.
Call "GlobalParameters.Keyboard.CustomShow();" on each form i need.
hope it helps

Listbox selectedindex property change doesn't update the UI

Using javascript, I am trying to change the selection of the listbox item like this:
function selectFirstActiveListItem(oListBox)
{
for (var i = 0; i < oListBox.options.length; i++)
{
oListBox.selectedIndex = i;
var szStatus = GetDomboBoxItemAttribute("Status", m_pdocConnectType.getXMLDOM(), oListBox);
if ("Enabled" == szStatus)
return;
}
oListBox.selectedIndex = 0;
}
Though the index correctly changes at the background, but it is not reflected on the UI. The listbox still shows the old selection.
What's going wrong?
try this instead:
oListBox.options[i].selected = true;
Oops! That was working and showing the correct result. My take on the behavior was incorrect there.