Isolated Storage to store recent lists, windows phone - windows-phone-7

enter code hereI have got isolated storage working but it's only storing one item.
I want to be able to store a list of favourites for the user to use in a list.
At the moment, i can store loads of stops, but when i open the application again, it only rememers the last item. and deletes the rest.
private void ApplicationBarFavouriteButton_Click(object sender, EventArgs e)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
// txtInput is a TextBox defined in XAML.
if (!settings.Contains("userData"))
{
settings.Add("userData", busStopName.Text);
}
else
{
settings["userData"] = busStopName.Text;
}
settings.Save();
MessageBox.Show("Bus Stop was added to your favourites");
}
then for displaying the list
if (IsolatedStorageSettings.ApplicationSettings.Contains("userData"))
{
listFav.Items.Add(IsolatedStorageSettings.ApplicationSettings["userData"] as string);
}
EDIT:
private void ApplicationBarFavouriteButton_Click(object sender, EventArgs e)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
List<string> favourites = settings["favourites"] as List<string>;
if (favourites == null)
{
favourites = new List<string>();
settings.Add("favourites", favourites);
}
favourites.Add(busStopName.Text);
settings["favourites"] = favourites;
}
displaying the data
if (IsolatedStorageSettings.ApplicationSettings.Contains("favourites"))
{
listFav.Items.Add(IsolatedStorageSettings.ApplicationSettings["favourites"] as List<string>);
}

You can access your settings like you would a hash/dictionary. So if your store information in settings["bob"], you will overwrite settings["bob"] when you next store something with the same key ("bob"). In your case, you're using the key "userData", every time you use settings["userData"] = "something";, you're overwriting what is stored in that key in the settings.
You could use something like the following (I've renamed your setting to "favourites" so that it is more descriptive of it's contents):
List<string> favourites;
settings.TryGetValue("favourites", out favourites);
if (favourites == null)
{
favourites = new List<string>();
settings.Add("favourites", favourites);
}
favourites.Add(busStopName.Text);
settings["favourites"] = favourites;
and for displaying it:
if (IsolatedStorageSettings.ApplicationSettings.Contains("userData"))
{
listFav.Items.AddRange(IsolatedStorageSettings.ApplicationSettings["favourites"] as List<string>);
}

You probably need to store a generic List of type string of Stops and then read this List from the ApplicationSettings, add a new stop to the List and then store the List back to the ApplicationSettings.

Related

Displaying data for radio button in epicor ERP10

I want to display data. I used AfterFieldChange method to display the data but it turns out the radio button doesn't change. I already insert the data customer table, the BAQ (Business Activity Query) also work just that the screen form doesn't work.
private void UD24_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
//EpiDataView edvUD24 = ((EpiDataView)(this.oTrans.EpiDataViews["UD24"]));
//System.Data.DataRow edvUD24Row = edvUD24.CurrentDataRow;
EpiDataView view = oTrans.EpiDataViews["UD24"] as EpiDataView;
switch (args.Column.ColumnName)
{
case "Character03":
DataTable tblcust=customer(args.Row["Character03"].ToString());
if(tblcust!=null && tblcust.Rows.Count>0)
{
string client = tblcust.Rows[0]["Customer_client1_c"].ToString();
view.dataView[view.Row]["ShortChar04"] = client;
//MessageBox.Show(Client);
}
break;
}
}
After changing the data in the EpiDataView you need to call Notify to make it call the UI elements that need to be updated:
view.dataView[view.Row]["ShortChar04"] = client;
view.Notify(new Ice.Lib.Framework.EpiNotifyArgs(this, view.Row, NotifyType.Initialize));
Kieym, perhaps try adding EpiNotifyArgs into your declaration, like so:
private void UD24_AfterFieldChange(object sender, DataColumnChangeEventArgs args, EpiNotifyArgs args)

Value of Column Name DataGridView

I'm using Visual Studio 2010 and i'm developing a windows form. Right now I'm using a data grid view and i want to write some functions that would allow you to automaticlly edit the datagrid by just changing the text in the Datagrid view. Right now, I am able to get the actual value but I need the value of the column in order to use it as a parameter when i use ADO.net here's what my code looks like now
private void dgv_DataLookup_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
DialogResult dr;
dr = MessageBox.Show("Are you sure you want to edit this field?", "Edit Cell", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
DataGridViewCell editItemCell = dgv_DataLookup[dgv_DataLookup.CurrentCell.RowIndex, dgv_DataLookup.CurrentCell.ColumnIndex];
string editItem = editItemCell.Value.ToString();
}
}
this here gets me the value of the current cell that is currently selected. I tried doing something like this
DataGridViewColumns columnCells = dgv_DataLookup.CurrentCell.ColumnIndex.Value.ToString()... something that would represent this but actual code. thanks!
According to what I understand you want to edit the value within a field, you can choose the value in this way.
private void button2_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to edit this field?",Application.ProductName.ToString(),MessageBoxButtons.YesNo)== DialogResult.Yes)
{
string editItem = this.dataGridView1.Rows[this.dataGridView1.CurrentRow.Index].Cells["NameField"].Value.ToString();
}
}
Bye

unable to parse the xml query using Linq

I am developing a sample Twitter app for Windows phone 7. In my code to display some details of user, used the following code.
void ShowProfile()
{
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Profile_DownloadCompleted);
client.DownloadStringAsync(new Uri("http://api.twitter.com/1/users/show.xml?user_id=" + this.id));
}
void Profile_DownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{ return; }
if (e.Result == null) MessageBox.Show("NUlllllllllll");
XElement Profile = XElement.Parse(e.Result);
var ProfileDetails = (from profile in Profile.Descendants("user")
select new UserProfile
{
UserName = profile.Element("screen_name").Value,
ImageSource = profile.Element("profile_image_url").Value,
Location = profile.Element("location").Value,
TweetsCount = profile.Element("statuses_count").Value,
}).FirstOrDefault();
LayoutRoot.DataContext = ProfileDetails;
}
Here, LayoutRoot is the Grid name. But the data binding doesn't work.
Infact, when kept a Break point it seems there is no data in the ProfileDetails object. But I could observe that e.Result contains the required data in the XML format.
Can any body figureout where I am going wrong??
Thanks in advance.
You have used XElement.Parse so Profile represents the single root <user> that API request would have returned. You are then trying to look for user elements inside it which of course makes no sense.
Try XDocument.Parse instead. Also does it really make any sense assigning a IEnumerable<UserProfile> to the data context when that list can only ever contain 1 entry?

Basic Eventhandler Question

Ok right now I have an object containing 3 strings, along with setters and getters. Now I have two questions -
First, I'm new to C# is there any way to optimize the following methods and make them more efficient?
void getSearchResults(object sender, RoutedEventArgs e)
{
string baseURL = "http://api.search.live.net/xml.aspx?Appid=<MyAPPID>&query=%22";
string companyName = ((TaxiCompany)sender).CoName;
string formatAndKey = "%22&sources=web";
WebClient c = new WebClient();
c.DownloadStringAsync(new Uri(baseURL + companyName + formatAndKey));
c.DownloadStringCompleted += new DownloadStringCompletedEventHandler(findTotalResults);
}
//Parses search XML result to find number of results
void findTotalResults(object sender, DownloadStringCompletedEventArgs e)
{
lock (this)
{
string s = e.Result;
XmlReader reader = XmlReader.Create(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(s)));
String results = "";
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name.Equals("web:Total"))
{
results = reader.ReadInnerXml();
break;
}
}
}
}
}
Second, I'm initializing an object - new Taxi Company (String name, String Phone, String Results). I've got name and number and I need to call the above two functions to get noOfResults so that I can initialize the object. However, I seem to run into a bunch of issues with the event handlers.
I've primarily been a web dev, so there might be something really basic I'm missing here. I have a feeling setting up the bing methods to return a string back to the constructor might be th easiest, but not quite sure how.
First of all, you don't need the lock on the main page. Then, I would say that your XmlReader block should be replaced with the LINQ-to-XML variation called XDocument, that will allow you to access the XML document with a single, elegant line:
XDocument doc = XDocument.Parse(e.Result);
Once you have the document, you can check whether it contains a specific XNode.

DropDownList in C#, getting DropDownList items overflow after every time using selecting an item

well the problem is that i am trying to get DDL to:
1. Recive catagories from a DB tabel - working
2. OnChange select from a different table the products by the item in the DDL - working
had a problem with No1 but fixed that problem. i found out that to get No1 working i have to use postback. did that and every thing in that part is working well and actualy every thing is working...but my hug problem (and i cant find any good answer for it) is that every time i change the item i a getting all the times all over again(i have initialy 8 item - secont time 16 - 24 etc....)
tried to use: ddlCatagories.Items.Clear();
when i use that i am not getting any duplicates but then, i am not getting any thing, it takes the first catagory from the list every time, no matter what i chose in the list..
trying to figure it out for the past week...please help :-)
public partial class selectNamesFromCatagories : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ddlCatagories.Items.Clear();
SqlDataReader dr = DbHelper.ExecuteReader(
sqlConn1.home,
"spSelectNamesFromCatagories");
while (dr.Read())
{
ListItem li = new ListItem(dr["CategoryName"].ToString());
ddlCatagories.Items.Add(li);
}
dr.Close();
}
protected void ddlCatagories_SelectedIndexChanged(object sender, EventArgs e)
{
SqlDataReader dr = DbHelper.ExecuteReader(
sqlConn1.home,
"spProductsByCatagoryID",
new SqlParameter("#catName", ddlCatagories.Text)
);
while (dr.Read())
{
TableRow tr = new TableRow();
for (int i = 0; i < dr.FieldCount; i++)
{
TableCell td = new TableCell();
td.Text = dr[i].ToString();
tr.Controls.Add(td);
}
tblProductsByCatagories.Controls.Add(tr);
}
}
}
Only populate the DropDownList on first load by checking whether the page has not posted back ie.
if (!Page.IsPostBack)
{
// Populate list
}
I agree with Dan and would add the following as well if you have any ajax enabled controls as they may generate callbacks.
if (!Page.IsPostBack && !Page.IsCallBack)
{
// Populate list
}

Resources