I'm using the GridView control in WP7 to show records from isolated storage. I'm displaying these
records at page load event of the page. The GridViewPage has 4 columns originally
but when I come back to GridViewPage visiting other page the gridview
showing duplicate columns( 8 columns this time).
Next time again I come back to GridViewPage it is showing 12 columns,
but I don't see any changes in the corresponding XAML page.
But one thing before assigning value to ItemSource of the gridView I'm storing records from the isostore into one IList varialbe making some changes and assigning that IList variable to ItemSource of GridView.
private void GridViewPage_load(object sender, RoutedEventArgs r)
{
System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
dt.Interval = new TimeSpan(0, 0, 0, 1,0); // 1 seconds
dt.Tick += new EventHandler(dt_Tick);
dt.Start();
}
void dt_Tick(object sender, EventArgs e)
{
IList rawList = DBHelperMeeting.GetData();
int count = rawList.Count;
for (int i = 0; i < count; i++)
{
/* in following lines i've written logic to get date and start_time from
table records stored in IList variable-rawList and forming a DateTime
variable
*/
string endDate =Convert.ToDateTime(rawList.ElementAt(i).Date.ToString()).ToShortDateString();
endDate += " "+rawList.ElementAt(i).End_Time;
string startDate = Convert.ToDateTime(rawList.ElementAt(i).Date.ToString()).ToShortDateString();
startDate+=" "+rawList.ElementAt(i).Start_Time;
if ((bool)rawList.ElementAt(i).Flag == true)
{
TimeSpan st = Convert.ToDateTime(startDate) - DateTime.Now;
//MessageBox.Show(st.ToString());
TimeSpan et = Convert.ToDateTime(endDate) - DateTime.Now;
//MessageBox.Show(et.ToString());
if (st.Seconds < 0)
{
if (et.Seconds < 0)
{
rawList.ElementAt(i).Flag = false;
rawList.ElementAt(i).Rem_Time = "Meeting Finished";
}
else
{
rawList.ElementAt(i).Rem_Time = "Meeting Started";
}
}
else if (st.Minutes > 0 && ((st.Hours * 60) + (st.Minutes)) < 16)
{
rawList.ElementAt(i).Rem_Time = st.Minutes.ToString() + " Min.";
}
}
}
GridView1.ItemsSource = rawList;
}
Actually i want to update the Rem_Time field of each record( i.e. meeting) according to time ( Rem_Time shows the remaining time for meeting)
Loaded event is raised all the time when all page components are loaded, even when you come back from another page. You need to load elements in constructor, for example.
Related
I am trying to create a dynamic tablelayout which creates adds a skill and gives that skill 1 level and a increase decrease button. I am struggling with having the buttons access the level label. I thought about finding the location of the button that was clicked, but could figure out how to do that.
In advance, Thank you.
example:
1
this is what i have so far:
private void skilladded(object sender, EventArgs e)
{
int i = 1;
int[] position= { 0,0};
bool test = false;
//string select;
int k=0;
for (i=1;i<=skillstableLayoutPanel.RowCount;i++)
{
Control c= skillstableLayoutPanel.GetControlFromPosition(0,i);
if (c!=null&&addskillswin.selected==c.Text)
{
test = true;
k = i;
break;
}
else if(c==null)
{
k = i;
break;
}
}
if (test==false)
{
Label newskill = new Label();
Label newskilllvl = new Label();
TableLayoutPanel buttontable = new TableLayoutPanel();
Button up = new Button();
Button down = new Button();
buttontable.ColumnCount = 2;
buttontable.RowCount = 1;
buttontable.RowStyles.Add(new RowStyle(SizeType.Percent,100f));
buttontable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent,50f));
buttontable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50f));
buttontable.Margin = new Padding(0,0,0,0);
buttontable.Dock = DockStyle.Fill;
buttontable.Controls.Add(up, 0, 0);
buttontable.Controls.Add(down, 1, 0);
up.BackgroundImage = Properties.Resources.up;[enter image description here][2]
down.BackgroundImage = Properties.Resources.down;
up.BackgroundImageLayout=ImageLayout.Stretch;
down.BackgroundImageLayout = ImageLayout.Stretch;
newskill.Text = addskillswin.selected;
newskilllvl.Text = "1";
up.Margin = new Padding(0, 0, 0, 0);
down.Margin = new Padding(0, 0, 0, 0);
skillstableLayoutPanel.Controls.Add(newskill,0,k);
skillstableLayoutPanel.Controls.Add(newskilllvl, 1, k);
skillstableLayoutPanel.Controls.Add(buttontable, 2, k);
skillavaillabel.Text = (Convert.ToInt32(skillavaillabel.Text) - 1).ToString();
skillpointlvl = Convert.ToInt32(newskilllvl.Text);
up.MouseClick += new MouseEventHandler(skillup);
down.MouseClick += new MouseEventHandler(skilldown);
}
if (test==true)
{
skillstableLayoutPanel.GetControlFromPosition(1, k).Text = (Convert.ToInt32(skillstableLayoutPanel.GetControlFromPosition(1, k).Text) + 1).ToString();
skillavaillabel.Text = (Convert.ToInt32(skillavaillabel.Text) -1).ToString();
}
}
private void skillup(object sender, EventArgs e)
{
skillpointlvl++;
}
private void skilldown(object sender, EventArgs e)
{
skillpointlvl--;
}
Instead of this:
up.MouseClick += new MouseEventHandler(skillup);
down.MouseClick += new MouseEventHandler(skilldown);
Try something like this:
up.MouseClick += ((o, me) =>
{
int currentLevel = Int32.Parse(newskilllvl.Text);
currentLevel++;
newskilllvl.Text = currentLevel.ToString();
});
down.MouseClick += ((o, me) =>
{
int currentLevel = Int32.Parse(newskilllvl.Text);
currentLevel--;
newskilllvl.Text = currentLevel.ToString();
});
Your skillup or skilldown event handler could potentially process each sender and see from which button the click originated, but you'd have to uniquely name each button and do a lot of string comparisons to see which button corresponds to which skill level label. The code above adds an anonymous handler to each button, which allows us to essentially tie the button being clicked to its corresponding skill label.
Personally though, I would not store all these values in labels like you have done. I would either store them in properties on the form, or better yet in a class of their own. I would also put all this logic somewhere else beside the form, like in a Presenter or Controller (or class library), and follow a design pattern such as MVC or MVP. This will make maintaining and changing the application easier in the long run.
Also, consider using camel case and Pascal case for your variable names. All lowercase variables are harder for experienced programmers to read.
Here is the code I am using for delete functionality.
In RadgridItemdatabound funtion, I have to include this...
foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
{
dataItem["TemplateDeleteColumn"].Attributes.Add("onclick","CellClick('" + dataItem.ItemIndex + "','" + col.UniqueName + "');");
}
Then I have to create Itemcommand function.
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "DeleteSelected")
{
GridDataItem item = (GridDataItem)e.Item;
var itemIndex = item.ItemIndex;
string LoginId = item.GetDataKeyValue("LoginId").ToString();
Int32 CampusCode = Convert.ToInt32(item.GetDataKeyValue("CampusCode"));
Definations def = new Definations();
Int32 Result = def.deleteUserAssignCampus(LoginId, CampusCode);
if (Result == 1)
{
BindDeptDatasimple();
cmbColumName.SelectedValue = "";
cmbDirection.SelectedValue = "";
Response.Redirect("UserCampus.aspx", false);
Session["deleteUserCampus"] = "Campus dissociated successfully.";
}
}
}
I could not get index of the selected row in the "var ItemIndex".
It always return zero index in ItemIndex. That's why the first row from the grid gets deleted. How I can get selected Index of selected row?
The item index will default to 0 because in your case you raise custom command
through MasterTableView's client object method.
You will have to make sure that in your custom JS function, CellClick, item index is passed into fireCommand client method via the 2nd argument.
masterTable.fireCommand("DeleteSelected", itemIndex);
Then in RadGrid1_ItemCommand event handler, you can retrieve the index value like this
GridDataItem item = (GridDataItem)e.Item;
var itemIndex = e.CommandArgument;
I have a form with a submitbutton which will get results from a database and updates a listview based on these results. If there is no result, a feedback message is shown. This all works fine.
Now I want to replace the submitlink with an IndicatingAjaxButton, so the user can see something happening when getting the result takes a long time.
The basic idea is this:
IndicatingAjaxButton submitLink = new IndicatingAjaxButton("submit", form) {
private static final long serialVersionUID = -4306011625084297054L;
#Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
Integer hourFrom = 0;
Integer hourTo = 0;
Integer minuteFrom = 0;
Integer minuteTo = 0;
hourFrom = Integer.parseInt(hour_from.getModelObject());
hourTo = Integer.parseInt(hour_to.getModelObject());
minuteFrom = Integer.parseInt(minute_from.getModelObject());
minuteTo = Integer.parseInt(minute_to.getModelObject());
Calendar from = Calendar.getInstance();
Calendar to = Calendar.getInstance();
Date dateFrom = date_from.getModelObject();
Date dateTo = date_to.getModelObject();
from.setTime(dateFrom);
to.setTime(dateTo);
from.set(Calendar.HOUR, hourFrom);
from.set(Calendar.MINUTE, minuteFrom);
to.set(Calendar.HOUR, hourTo);
to.set(Calendar.MINUTE, minuteTo);
if (topicQueueSelect.getModelObject() == null) {
error("Please select a message name.");
getSession().setAttribute("error", "");
}
if (to.before(from)) {
error("Date to must be after date from.");
getSession().setAttribute("error", "");
}
cal.setTimeInMillis(System.currentTimeMillis());
if (from.after(cal)) {
error("Date from must be in the past.");
getSession().setAttribute("error", "");
}
if (getSession().getAttribute("error") != null) {
getSession().removeAttribute("error");
return;
}
page.setModelObject(1);
List<Search> searchFields = (List<Search>) searchFieldsField
.getModelObject();
messageKeyDataList = messageController.search(
topicQueueSelect.getModelObject(), searchFields,
from.getTime(), to.getTime(),
maxResults.getModelObject(), page.getModelObject(),
sortorder);
if (messageKeyDataList.size() == 0) {
info("Search criteria didn't produce any results.");
result.setList(messageKeyDataList);
resultContainer.setVisible(false);
return;
}
resultContainer.setVisible(true);
resultSize = messageController.getResultSize();
int pages = (int) Math.ceil((float) resultSize
/ maxResults.getModelObject());
ArrayList<Integer> pageNumbers = new ArrayList<Integer>();
for (int n = 1; n <= pages; n++) {
pageNumbers.add(n);
}
page.setChoices(pageNumbers);
pageunder.setChoices(pageNumbers);
showing.setDefaultModelObject("Showing 1 to "
+ messageKeyDataList.size() + " out of " + resultSize
+ " messages");
lastSearch.put("topicQueue", topicQueueSelect.getModelObject());
lastSearch.put("searchFields", searchFields);
lastSearch.put("from", from.getTime());
lastSearch.put("to", to.getTime());
lastSearch.put("maxResults", maxResults.getModelObject());
result.setList(messageKeyDataList);
target.add(feedback);
}
};
The SubmitLink does show me either the ResultView with the new list, or the info message, the IndicatingAjaxButton doesn't. I know the form submit is called, because the system.out is being printed.
Any suggestions on this?
SubmitLink is non-Ajax component. Using it will repaint the whole page!
IndicatingAjaxButton is an Ajax component. You need to use the passed AjaxRequestTarget to add components which should be repainted with the Ajax response. For example the FeedbackPanel should be added to the AjaxRequestTarget.
I found that I had to do setOutputMarkupPlaceholderTag(true) on both the resultContainer and the feedback. After that adding them to the requesttarget works as expected.
i have a problem to add pivot item in pivot control ..i want to add pivot item in pivot(Mycontrol) when i add next button .code for next button
static int selectitem;
private void nextbuttonOnclick(object sender, RoutedEventArgs e)
{
if (selectitem != list.Count() - 1)
select(selectitem + 1);
else
{
select(0);
}
}
now it call the select method to add pivot item to pivot
void select(int i)
{
MyControl.Items.Clear();
pivotItem = new PivotItem();
Grid sta = new Grid();
WebBrowser wb = new WebBrowser();
sta.Background = new SolidColorBrush(Colors.White);
var address = "<h3>" + list.ElementAt(i).header + "</h3>" + "<br>" + "<img width=\"949\" height=\"449\" src=" + list.ElementAt(i).Imagee + " >" + "<br>" + list.ElementAt(i).Detail.ToString();
var ByteData = Encoding.UTF8.GetBytes(address);
System.Text.Encoding enc = System.Text.Encoding.UTF8;
string myString = enc.GetString(ByteData, 0, ByteData.Length);
try
{
wb.Loaded += (sendr, ev) =>
{
wb.NavigateToString(myString);
};
}
catch (Exception ex)
{
}
wb.Margin = new Thickness(0, 0, 0, 0);
sta.Children.Add(wb);
pivotItem.Content = sta;
MyControl.Items.Add(pivotItem);
try
{
if (i == -1)
MyControl.SelectedIndex = 0;
else
{
selectitem = i;
MyControl.SelectedIndex = i;
}
}
catch (IndexOutOfRangeException v)
{
}
}
but after adding one it shows a exception ie ArgumentException was unhandled
...thanx in advance
The ArgumentException is happening because of this line:
MyControl.Items.Clear();
That line removes all the items in the pivot control, but your internal selectitem variable doesn't account for that. In your code, there will always be only one pivot item (which sort of defeats the purpose of the pivot control). When you go to add item #2, the selectitem variable is set to 1 and the line MyControl.SelectedIndex = 1; cases the exception since there is only 1 pivot item (0 based arrays, and all that stuff).
Try removing the line that clears the pivot items above and see if it works for you. Otherwise, you're going to have to change the MyControl.SelectedIndex = i; line to be MyControl.SelectedIndex = 0;.
Just FYI - when I ran your sample, I needed to initialize selecitem to -1, not 0, or I got the same error message. I also added code to set the PivotItem.Header property to something so it was easier to flip between pivot items.
Just out of curiosity, why are you not doing this through DataBinding instead of all this code to load up items manually?
I have a datagridview2 on my form that has 4 columns and has data. I want to add a row at the end of it and fill it with data. But when i use 'Me.DataGridView2.Rows.Add()' it adds row but not the end of the datagridview. is there a way to add a blank row at the end of datagridview?
The last row in datagridview is to allow user to add row if he wants.
Set DataGridView2.AllowUserToAddRows = False
Then try to use Me.DataGridView2.Rows.Add() . It will Add a raw to the end of the
dataGridView
I would upvote #user1157690, but I don't have enough reputation to do so. In order to add a blank row to the bottom:
DataGridView2.AllowUserToAddRows = false;
for (int i = 0; i < 10; i++)
{
DataGridView2.Rows.Add();
}
DataGridView2.AllowUserToAddRows = true;
This would allow you to enter 10 blank rows programmatically in chronological order from oldest to newest while allowing the user to enter additional rows if necessary. This is the best method that I know of for allowing user flexibility and programmer consistency.
I tried and it adds the row at the end of the DataGridView.
I dragged a DataGridView and a button in the form.
Here is the code:
private void addRowbutton_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Add();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Columns.Add("ID", "Product ID");
dataGridView1.Columns.Add("Name", "Product Name");
dataGridView1.Columns.Add("Description", "Description");
dataGridView1.Columns.Add("Price", "Price");
for (int i = 0; i < 2; i++)
{
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dataGridView1);
row.Cells[0].Value = i;
row.Cells[1].Value = "Product " + i;
row.Cells[2].Value = "Description of Product " + i;
row.Cells[3].Value = "99.99";
dataGridView1.Rows.Add(row);
}
}
If you populate the datagridview via databind you cannot add a row programmatically.