I have a user-control contains a DropDownList, and this user-control is used inside another one. I am passing the selected value to the drop-down from the outer user control to the inner one, and I am tracking the value passed (during debugging) and the value is passed correctly, but at least the value is NOT set correctly!
Here is the code of the outer user-control
public int SelectedPhoneNumberCountryCode
{
get { return ucRecoveryPhoneNumber.SelectedPhoneNumberCountryCode; }
set { ucRecoveryPhoneNumber.SelectedPhoneNumberCountryCode = value; }
}
And this is the code of the inner user-control (ucRecoveryPhoneNumber)
public int SelectedPhoneNumberCountryCode
{
get { return int.Parse(DdlCountryPhoneCodes.SelectedValue); }
set { DdlCountryPhoneCodes.SelectedValue = value.ToString(); }
}
At the Page_Load, the value is passed correctly until the last step, but it is not set correctly! and the drop-down is always selected as the first value (default one).
Q What is wrong with this code? or What should be done to make it work?
Related
I'm not sure if I'm asking this properly. I have a datagrid where column 1 data can come from two different places depending on a switch bit. The first place is a periodic update of the view model column from the model. The second place is if I manually edit a cell of column 1. I have a custom column binding in the XAML code binds to a list of classes. The problem is that when I start typing in data, it gets overwritten by the periodic update. Is there a proper way to design what I am looking to accomplish?
Below is the pseudo code for what is bound to Column 1 of the datagrid.
public int Column1
{
get
{
if(mySwitch)
return this.NumList[0].Data;
else
return this.NumList[0].EditedData;
}
set
{
if (mySwitch)
{
//this gets set every few seconds
this.Numlist[0].Data = value;
this.OnPropertyChanged("mydata");
}
else
{ //this gets called only when mySwitch is false and I'm in edit mode.
this.Numlist[0].EditedData = value;
this.OnPropertyChanged("myediteddata");
}
}
}
Thanks
In my WinForm application when I want to add a row in xtragrid, I have a problem with getting the current value of the focused textbox.
Assume I have a textBox bind to Model.VchType.Title , Before I click Save button my focus is on txtTitle and I typed "title1" on it.
This is my code for Save button event:
Model.VchType row = xtraGrd.GetRow(xtraGrd.FocusedRowHandle) as Model.VchType;
I get null for row.Title after it hits the break point in this line of code.
And this problem only occurs when right before I click on save button focus is on txtTitle.
-------- UPDATE ------------
Here is some of code of model:
[System.ComponentModel.DataAnnotations.Schema.Table("vwVchType", Schema = "Sle")]
[Serializable]
public class VchType : Entity
{
private int _ID;
[System.ComponentModel.DataAnnotations.Schema.Column]
[RnDisplayName(typeof(Rnw.Sle.Properties.Resources), "ID")]
public override int ID
{
get
{
return _ID;
}
set
{
_ID = value;
}
}
private string _Title;
[System.ComponentModel.DataAnnotations.Schema.Column]
[RnDisplayName(typeof(Rnw.Sle.Properties.Resources), "Title")]
public string Title
{
get
{
return _Title;
}
set
{
_Title = value;
}
}
}
Also I created columns by designer.
I fill a bindingSource and set the property of the datasource of grid to this bindingsource in designer.
And I don't think problem is column name , because if before I click save button I focus on another controller, It works fine and I get value for row.Title.
You need to call
((GridView)xtraGrid.FocusedView).PostEditor();
or
gridView.PostEditor()this will save the current value to the editor EditValue.
Then you need to call view.UpdateCurrentRow() to validate the focused row and save its values to the data source.
So you need something like this
((GridView)xtraGrid.FocusedView).PostEditor();
((GridView)xtraGrid.FocusedView).UpdateCurrentRow();
Model.VchType row = xtraGrd.GetRow(xtraGrd.FocusedRowHandle) as Model.VchType;
You can focus another forms object before you save your data. So call:
anyControl.Select();
Before you save. This will close the open editor from your Textbox and post the changes to your DataSource. Normally this should be done by PostEditor(); which sometimes seems to lack.
I use viewstate in application where I have found that encapsulating viewstate in property is much more convenient.
Here is the code what I do in my code.
public List<TransactionEntity> TransactionData
{
get
{
if(ViewState["TransactionData"] == null)
return new List<TransactionEntity>();
return _TransactionData as List<TransactionEntity>();
}
set
{
How to set value to gridview from here ??
}
}
Now i have a gridview in user control which I need to bind everytime I assign value to this property.
Anyone knows how to do it.
Thanks.
Now i have a gridview in user control which I need to bind everytime I
assign value to this property.
Anyone knows how to do it
set
{
ViewState["TransactionData"] = value;
gridview.DataSource = value as List<TransactionEntity>; //check if null etc
gridview.DataBind();// ...
}
I try to make a get set statement but it doesn't work. I have no idea why.
Basically I have a form named form1 that contains a combo-box with names and a button.
The button opens a new form form2 that has a text box. I want to be able to add the text in the text box to the combo box in form1. I searched the web a bit and found that in order to do so i need to create get and set statement instead of playing with the privacy of the controls.
The set and get statement doesn't work. It says only assignment call increment decrement and new object can be used as statement.
Much appreciate your help.
public string GuideNameFunc(){
Get { return GuideName.Text; }
set { GuideName.Text = value; }
}
Just remove it () from your code.
public string GuideNameFunc{
get { return GuideName.Text; }
set { GuideName.Text = value; }
}
public string GuideNameField{
get { return GuideName.Text; }
set { GuideName.Text = value; }
}
I have for example property like this:
private string foobar;
public string Foobar
{
get
{
return this.foobar;
}
set
{
if (value != this.foobar)
{
// here I want to check if value is correct
if(value != something)
{
this.foobar = value;
this.NotifyPropertyChanged("Foobar");
}
else
{
value = null;
this.foobar = null;
this.NotifyPropertyChanged("Foobar");
}
}
}
}
Property is binded (MVVM) to Listview :
SelectedItem="{Binding Foobar, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}
.
And when user changes value in list, selecteditem is changed and value is set in setter. I code is ok, when user selected incorrect value, to value and foobar null is assigned. But in WPF still selected value is displayed. When I set breakpoint in getter I can see that it return null too. How to refresh WPF to clear selected value in listview ? It shoud be empty like at the begin.
Thanks
The problem with your code is that you want to override value assigned by binding in your setter method. This will not work because control will not update on next property change for simple reason that it has invoked it by setting property. To implement validation on your values try this build in mechanism.
i would prefer using IDataErrorInfo and dont use property setter logic. the main advantage is that your property value in your viewmodel and your view are always the same and your viewmodel has the information wether the value is ok or not.