How to set a Picker with a value in its SelectedIndex property2019 Community Moderator ElectionHow do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?Get int value from enum in C#How to loop through all enum values in C#?How to Sort a List<T> by a property in the objectComboBoxEdit SelectedIndex always -1WPF `ComboBox` ItemsSource property is changed the SelectedItem property is being set to nullPicker itemlist and index updateXamarin Forms. How can I bind picker's selected item to be displayed in picker field on switching view?Xamarin picker, not setting default value

How are passwords stolen from companies if they only store hashes?

What are substitutions for coconut in curry?

Why one should not leave fingerprints on bulbs and plugs?

How to get the n-th line after a grepped one?

Is a party consisting of only a bard, a cleric, and a warlock functional long-term?

Are Roman Catholic priests ever addressed as pastor

How difficult is it to simply disable/disengage the MCAS on Boeing 737 Max 8 & 9 Aircraft?

Aluminum electrolytic or ceramic capacitors for linear regulator input and output?

World War I as a war of liberals against authoritarians?

Why is a white electrical wire connected to 2 black wires?

Book about superhumans hiding among normal humans

What is "focus distance lower/upper" and how is it different from depth of field?

Is it good practice to use Linear Least-Squares with SMA?

What's the meaning of a knight fighting a snail in medieval book illustrations?

Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?

Why did it take so long to abandon sail after steamships were demonstrated?

Why do newer 737s use two different styles of split winglets?

A diagram about partial derivatives of f(x,y)

Recruiter wants very extensive technical details about all of my previous work

Why do tuner card drivers fail to build after kernel update to 4.4.0-143-generic?

How to pronounce "I ♥ Huckabees"?

Print a physical multiplication table

Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?

I am confused as to how the inverse of a certain function is found.



How to set a Picker with a value in its SelectedIndex property



2019 Community Moderator ElectionHow do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?Get int value from enum in C#How to loop through all enum values in C#?How to Sort a List<T> by a property in the objectComboBoxEdit SelectedIndex always -1WPF `ComboBox` ItemsSource property is changed the SelectedItem property is being set to nullPicker itemlist and index updateXamarin Forms. How can I bind picker's selected item to be displayed in picker field on switching view?Xamarin picker, not setting default value










0















I want that when opening a screen that loads a Picker, this control is set with the value "EXPIRED" ("CADUCADOS"), in the following way ...



SetPicker



The problem is that this picker has other values besides "EXPIRED" ("CADUCADOS") as shown in the following image...



Picker



The question is how can I set my Picker control to the "EXPIRED" value? , for this I occupy the SelectedIndex property supplied to an attribute of type int in the following way



 <!--PICKER-->
<Picker
Title="Seleccione un estado"
SelectedIndex="Binding Index, Mode=TwoWay"
ItemsSource="Binding ListaEstados, Mode=TwoWay"
ItemDisplayBinding="Binding Estado"
SelectedItem="Binding SelectedEstado">
</Picker>


My ViewModel.CS:



 int index;

public int Index

get

return index;

set

if (index != value)

index = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Index)));





This is the method that fills the Picker with a List of "States" and it is here that I set the value of the Index ...



 private void LoadPickerEstados()

ListaEstados.Clear();

var caducados = new Estados

IdEstado = 0,
Estado = "CADUCADOS",
;

var aprobaryplanificar = new Estados

IdEstado = 1,
Estado = "POR APROBAR Y PLANIFICAR",
;

var planificar = new Estados

IdEstado = 4,
Estado = "POR PLANIFICAR",
;

ListaEstados.Add(caducados);
ListaEstados.Add(aprobaryplanificar);
ListaEstados.Add(planificar);

Index = 1;




The problem is that when setting Index = 0 => this returns the Placeholder, when setting Index = 1 => it returns For approval and planning ("POR APROBAR Y PLANIFICAR") and when setting Index = 2 => it returns for planning ("POR PLANIFICAR"), but I can never get the value "EXPIRED" ("CADUCADOS")!!



What's going on? Am I using the right property?
How can I set the picker with the right value? any help for me?










share|improve this question

















  • 1





    The default value of an int is 0. So when you set Index = 0 it won't do anything because index is equal to 0 already. This might be the problem. Could you try removing the index != value check?

    – Knoop
    Mar 6 at 22:52







  • 1





    Can you show your sample project.The problem may be SelectedItem and SelectedIndex have some conflict using in them.

    – Junior Jiang - MSFT
    Mar 7 at 2:28











  • Please set SelectedIndex=-1 when you are loading the page.

    – Adit Kothari
    Mar 8 at 5:32















0















I want that when opening a screen that loads a Picker, this control is set with the value "EXPIRED" ("CADUCADOS"), in the following way ...



SetPicker



The problem is that this picker has other values besides "EXPIRED" ("CADUCADOS") as shown in the following image...



Picker



The question is how can I set my Picker control to the "EXPIRED" value? , for this I occupy the SelectedIndex property supplied to an attribute of type int in the following way



 <!--PICKER-->
<Picker
Title="Seleccione un estado"
SelectedIndex="Binding Index, Mode=TwoWay"
ItemsSource="Binding ListaEstados, Mode=TwoWay"
ItemDisplayBinding="Binding Estado"
SelectedItem="Binding SelectedEstado">
</Picker>


My ViewModel.CS:



 int index;

public int Index

get

return index;

set

if (index != value)

index = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Index)));





This is the method that fills the Picker with a List of "States" and it is here that I set the value of the Index ...



 private void LoadPickerEstados()

ListaEstados.Clear();

var caducados = new Estados

IdEstado = 0,
Estado = "CADUCADOS",
;

var aprobaryplanificar = new Estados

IdEstado = 1,
Estado = "POR APROBAR Y PLANIFICAR",
;

var planificar = new Estados

IdEstado = 4,
Estado = "POR PLANIFICAR",
;

ListaEstados.Add(caducados);
ListaEstados.Add(aprobaryplanificar);
ListaEstados.Add(planificar);

Index = 1;




The problem is that when setting Index = 0 => this returns the Placeholder, when setting Index = 1 => it returns For approval and planning ("POR APROBAR Y PLANIFICAR") and when setting Index = 2 => it returns for planning ("POR PLANIFICAR"), but I can never get the value "EXPIRED" ("CADUCADOS")!!



What's going on? Am I using the right property?
How can I set the picker with the right value? any help for me?










share|improve this question

















  • 1





    The default value of an int is 0. So when you set Index = 0 it won't do anything because index is equal to 0 already. This might be the problem. Could you try removing the index != value check?

    – Knoop
    Mar 6 at 22:52







  • 1





    Can you show your sample project.The problem may be SelectedItem and SelectedIndex have some conflict using in them.

    – Junior Jiang - MSFT
    Mar 7 at 2:28











  • Please set SelectedIndex=-1 when you are loading the page.

    – Adit Kothari
    Mar 8 at 5:32













0












0








0








I want that when opening a screen that loads a Picker, this control is set with the value "EXPIRED" ("CADUCADOS"), in the following way ...



SetPicker



The problem is that this picker has other values besides "EXPIRED" ("CADUCADOS") as shown in the following image...



Picker



The question is how can I set my Picker control to the "EXPIRED" value? , for this I occupy the SelectedIndex property supplied to an attribute of type int in the following way



 <!--PICKER-->
<Picker
Title="Seleccione un estado"
SelectedIndex="Binding Index, Mode=TwoWay"
ItemsSource="Binding ListaEstados, Mode=TwoWay"
ItemDisplayBinding="Binding Estado"
SelectedItem="Binding SelectedEstado">
</Picker>


My ViewModel.CS:



 int index;

public int Index

get

return index;

set

if (index != value)

index = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Index)));





This is the method that fills the Picker with a List of "States" and it is here that I set the value of the Index ...



 private void LoadPickerEstados()

ListaEstados.Clear();

var caducados = new Estados

IdEstado = 0,
Estado = "CADUCADOS",
;

var aprobaryplanificar = new Estados

IdEstado = 1,
Estado = "POR APROBAR Y PLANIFICAR",
;

var planificar = new Estados

IdEstado = 4,
Estado = "POR PLANIFICAR",
;

ListaEstados.Add(caducados);
ListaEstados.Add(aprobaryplanificar);
ListaEstados.Add(planificar);

Index = 1;




The problem is that when setting Index = 0 => this returns the Placeholder, when setting Index = 1 => it returns For approval and planning ("POR APROBAR Y PLANIFICAR") and when setting Index = 2 => it returns for planning ("POR PLANIFICAR"), but I can never get the value "EXPIRED" ("CADUCADOS")!!



What's going on? Am I using the right property?
How can I set the picker with the right value? any help for me?










share|improve this question














I want that when opening a screen that loads a Picker, this control is set with the value "EXPIRED" ("CADUCADOS"), in the following way ...



SetPicker



The problem is that this picker has other values besides "EXPIRED" ("CADUCADOS") as shown in the following image...



Picker



The question is how can I set my Picker control to the "EXPIRED" value? , for this I occupy the SelectedIndex property supplied to an attribute of type int in the following way



 <!--PICKER-->
<Picker
Title="Seleccione un estado"
SelectedIndex="Binding Index, Mode=TwoWay"
ItemsSource="Binding ListaEstados, Mode=TwoWay"
ItemDisplayBinding="Binding Estado"
SelectedItem="Binding SelectedEstado">
</Picker>


My ViewModel.CS:



 int index;

public int Index

get

return index;

set

if (index != value)

index = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Index)));





This is the method that fills the Picker with a List of "States" and it is here that I set the value of the Index ...



 private void LoadPickerEstados()

ListaEstados.Clear();

var caducados = new Estados

IdEstado = 0,
Estado = "CADUCADOS",
;

var aprobaryplanificar = new Estados

IdEstado = 1,
Estado = "POR APROBAR Y PLANIFICAR",
;

var planificar = new Estados

IdEstado = 4,
Estado = "POR PLANIFICAR",
;

ListaEstados.Add(caducados);
ListaEstados.Add(aprobaryplanificar);
ListaEstados.Add(planificar);

Index = 1;




The problem is that when setting Index = 0 => this returns the Placeholder, when setting Index = 1 => it returns For approval and planning ("POR APROBAR Y PLANIFICAR") and when setting Index = 2 => it returns for planning ("POR PLANIFICAR"), but I can never get the value "EXPIRED" ("CADUCADOS")!!



What's going on? Am I using the right property?
How can I set the picker with the right value? any help for me?







c# xamarin mvvm xamarin.forms picker






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 6 at 21:00









Bodega PangalBodega Pangal

626




626







  • 1





    The default value of an int is 0. So when you set Index = 0 it won't do anything because index is equal to 0 already. This might be the problem. Could you try removing the index != value check?

    – Knoop
    Mar 6 at 22:52







  • 1





    Can you show your sample project.The problem may be SelectedItem and SelectedIndex have some conflict using in them.

    – Junior Jiang - MSFT
    Mar 7 at 2:28











  • Please set SelectedIndex=-1 when you are loading the page.

    – Adit Kothari
    Mar 8 at 5:32












  • 1





    The default value of an int is 0. So when you set Index = 0 it won't do anything because index is equal to 0 already. This might be the problem. Could you try removing the index != value check?

    – Knoop
    Mar 6 at 22:52







  • 1





    Can you show your sample project.The problem may be SelectedItem and SelectedIndex have some conflict using in them.

    – Junior Jiang - MSFT
    Mar 7 at 2:28











  • Please set SelectedIndex=-1 when you are loading the page.

    – Adit Kothari
    Mar 8 at 5:32







1




1





The default value of an int is 0. So when you set Index = 0 it won't do anything because index is equal to 0 already. This might be the problem. Could you try removing the index != value check?

– Knoop
Mar 6 at 22:52






The default value of an int is 0. So when you set Index = 0 it won't do anything because index is equal to 0 already. This might be the problem. Could you try removing the index != value check?

– Knoop
Mar 6 at 22:52





1




1





Can you show your sample project.The problem may be SelectedItem and SelectedIndex have some conflict using in them.

– Junior Jiang - MSFT
Mar 7 at 2:28





Can you show your sample project.The problem may be SelectedItem and SelectedIndex have some conflict using in them.

– Junior Jiang - MSFT
Mar 7 at 2:28













Please set SelectedIndex=-1 when you are loading the page.

– Adit Kothari
Mar 8 at 5:32





Please set SelectedIndex=-1 when you are loading the page.

– Adit Kothari
Mar 8 at 5:32












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032056%2fhow-to-set-a-picker-with-a-value-in-its-selectedindex-property%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032056%2fhow-to-set-a-picker-with-a-value-in-its-selectedindex-property%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved