I wanted to ask how can I display selected month from calendar and display into my text box? I tried to use ToString(), but it still didn't work. I'm thinking there's difference in date picker and calendar, still not sure. Can anyone please help me out here? Thanks alot. Here's my coding;
In xaml;
Calendar Name ="dteSelectedMonth" DisplayMode="Year" SelectionMode="SingleDate" DisplayModeChanged="dteSelectedMonth_DisplayModeChanged" DisplayDateChanged="monthCalendar_DataChanged"
In xaml.cs;
private void monthCalendar_DataChanged(object sender, CalendarDateChangedEventArgs e)
{
monthDisplay.Text = dteSelectedMonth.SelectedDate.ToString();
}
You could get the selected month using the DisplayDate property. Make sure that the IsLoaded property returns true before you try to set the Text property:
private void monthCalendar_DataChanged(object sender, CalendarDateChangedEventArgs e)
{
if (IsLoaded && dteSelectedMonth.DisplayDate != null)
monthDisplay.Text = dteSelectedMonth.DisplayDate.ToString("MMM");
}
Use CalendarDateChangedEventArgs object and its property AddedDate. When the event is fired, it will contain the previously selected day in the new month. Then you can convert it to any string format, e.g. to get the month.
Please check your monthDisplay textbox is null or not. This happens because the displayDteChanged event fires before the initialization of the textbox (If you have the declaration of TextBox before that of Calendar). Add a null check to handle this.
if (monthDisplay != null)
monthDisplay.Text = e.AddedDate?.Month.ToString();
Related
how can I reset or clear the content of CalendarDatePicker and/or TimePicker in UWP? I want to create a button (ex. RESET), when I click on the button, the CalendarDatePicker and TimePicker will clear the date and time which was selected before and will show back the PlaceHolder Text. I could not find any methods to do this. Is there a way? Thanks...
Try to set the Date property of the CalendarDatePicker or the SelectedTime property of the TimePicker to null:
private void Button_Click(object sender, RoutedEventArgs e)
{
calendarDatePicker1.Date = null;
timePicker1.SelectedTime = null;
}
In case anyone else comes across this, you have to set the SelectedDate for DatePicker or SelectedTime for TimePicker to null.
For example:
(FindName("myDatePickerName") as DatePicker).SelectedDate = null;
hello i'm new to xamarin forms and i did some searching but didn't find much.
i have a list of Items displayed on a page and i would like to refresh that list when the user choose from the picker.
for example when the user chose monthly from the picker the list must be refreshed and show the items for this month i already have 3 functions functionDaily, functionMonthly, functionYearly that return ObservableCollection but i don't know how to refresh the list when the user choose from the picker if somebody can help me Thanks
There are two ways to do it:
Using code behind
The pickers have an event called SelectedIndexChanged, that tell you when you change an element of your picker, when it raises you can update the source of your list, for example:
picker.SelectedIndexChanged += (sender, args) =>
{
if (!picker.SelectedIndex == -1)
{
if(picker[picker.SelectedIndex] == "By Day")
myList.ItemSource= functionDaily();
else if(picker[picker.SelectedIndex] == "By Month")
myList.ItemSource= functionMonthly();
else if(picker[picker.SelectedIndex] == "By Year")
myList.ItemSource= functionYearly();
}
};
Using the ViewModel
Is almost the same, just instead of using the SelectedIndexChanged method, you can use the property SelectedItem, create a property and binding to it, and when the property change update your ItemSource (Your ItemSource should be binding to a List on the ViewModel).
i found the answer thank you guys if somebody is facing the same problem here is the solution
void Handle_SelectedIndexChanged(object sender, System.EventArgs e)
{
picker = sender as Picker;
if(picker.SelectedItem.Equals("Monthly")){
ListActions.ItemsSource = am.GetMonthlyActionsByUserAndDate(CurrentUser.GetUser, DateTime.Now);
}
if(picker.SelectedItem.Equals("Yearly")){
ListActions.ItemsSource = am.GetYearlyActionsByUserAndDate(CurrentUser.GetUser, DateTime.Now);
}
if (picker.SelectedItem.Equals("Daily"))
{
ListActions.ItemsSource = am.GetDailyActionsByUserAndDate(CurrentUser.GetUser, DateTime.Now);
}
}
I have a timepicker control from Xceed WPF toolkit.
1. How i can get user selected time input value from it and put it in a textbox?
2. How i can add some integer value stored in a variable and add them as minutes to the timepicker time?
Thanks
private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
mytimepicker = new TimePicker();
if (mytimepicker.Value != null)
{
textBox1.Text = mytimepicker.Value.ToString();
}
}
This shows how to use the Xceed DatePicker:
http://www.c-sharpcorner.com/uploadfile/mahesh/wpf-datepicker/
You want to watch the SelectedDatesChanged event.
I am trying to associate a label with the ComboBox selected value but That label is not getting triggered.What is wrong with my code?
private void comboBoxCrewMember_SelectedIndexChanged(object sender, EventArgs e)
{
string crewMemberName=comboBoxCrewMember.Text;//ComboBox
string rankName=crewMemberManager.GetRankName(crewMemberName);
lblRankValue.Text = rankName;//label
}
My ComboBox consists of name of crew memebers which are selected and the label consists of rank of that particular crew member which is fetched by the method GetRankName.
On execution,I get the whole list of crew members'names but on selecting those names nothing happens to the label.
its quite simple bro..
private void comboBoxCrewMember_SelectedIndexChanged(object sender, EventArgs e)
{
string crewMemberName=comboBoxCrewMember.SelectedValue.ToString();
lblRankValue.Text = crewMemberManager.GetRankName(crewMemberName);
}
what u need to make sure ix that GetRankName() is returning only one value.. and thats it..
hope it helps
you can minimize thix code even..
like this
private void comboBoxCrewMember_SelectedIndexChanged(object sender, EventArgs e)
{
lblRankValue.Text = crewMemberManager.GetRankName(comboBoxCrewMember.SelectedValue.ToString(););
}
Make sure your Event is bound
Make sure your crewMemberManager.GetRankName(crewMemberName); method works fine
Make sure your ComboBox text is the value you want to parse to the crewMemberManager.GetRankName(crewMemberName); method
IF I were use , I would you something like below to retrieve the SelectedValue of combobox
comboBox1.SelectedIndex;selectedItem.ToString()
Object selectedItem = comboBox1.SelectedItem;
crewMemberManager.GetRankName(selectedItem.ToString());
And also I don' think your problem is with ComboBox or comboBox's selection, I think that your crewMemberManager.GetRankName(crewMemberName); method is caussing this issue , Please make sure that your crewMemberManager.GetRankName(crewMemberName); method works fine,
string crewMemberName=comboBoxCrewMember.Text;//ComboBox
the above will give you a string "crewMemberName", now make sure that the bellow method
crewMemberManager.GetRankName(crewMemberName)
is return type of string and it is written like bellow in the file
public string crewMemberManager.GetRankName(string name)
if not do same otherwise please provide that method for further verification.
In winforms, you need to click the combobox twice to properly activate it - the first time to focus it, the second time to actually get the dropdown list.
How do I change this behavior so that it activates on the very first click?
This is for DATAGRIDVIEW combobox.
I realize this is an old question, but I figured I would give my solution to anyone out there that may need to be able to do this.
While I couldn't find any answers to do exactly this... I did find an answer to a different question that helped me.
This is my solution:
private void datagridview_CellEnter(object sender, DataGridViewCellEventArgs e)
{
bool validClick = (e.RowIndex != -1 && e.ColumnIndex != -1); //Make sure the clicked row/column is valid.
var datagridview = sender as DataGridView;
// Check to make sure the cell clicked is the cell containing the combobox
if(datagridview.Columns[e.ColumnIndex] is DataGridViewComboBoxColumn && validClick)
{
datagridview.BeginEdit(true);
((ComboBox)datagridview.EditingControl).DroppedDown = true;
}
}
private void datagridview_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
datagridview.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
The above code must be tied into the CellEnter event of the datagridview.
I hope this helps!
edit: Added a column index check to prevent crashing when the entire row is selected.
Thanks, Up All Night for the above edit
edit2: Code is now to be tied to the CellEnter rather than the CellClick event.
Thanks, HaraldDutch for the above edit
edit3: Any changes will committed immediately, this will save you from clicking in another cell in order to update the current combobox cell.
Set the following on your DataGridView:
EditMode = EditOnEnter
This is probably the easiest solution and has been the workaround for many users here on SO when this question gets asked.
EDIT :
Per here do the following:
Set the Editmode:
EditMode = EditOnKeystrokeOrF2
Modify the EditingControlShowing event on the datagridview:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox ctl = e.Control as ComboBox;
ctl.Enter -= new EventHandler(ctl_Enter);
ctl.Enter += new EventHandler(ctl_Enter);
}
void ctl_Enter(object sender, EventArgs e)
{
(sender as ComboBox).DroppedDown = true;
}
This will get you your desired results. Let me know if that doesn't do it.
I changed only the EditMode property of the datagridview to EditOnEnter and it's working perfectly.
EditMode = EditOnEnter
If you set the entire grid to EditOnEnter, you can get some pretty funky activity when you are on a text column. Here's my solution, which should be self explanatory. If you did not know the column names, you could just check the cell type on mousemove.
Private Sub GridView_CellMouseMove(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles GridView.CellMouseMove
Select Case GridView.Columns(e.ColumnIndex).Name
Case "Ad_Edit", "Size_Caption", "Demo_Code"
GridView.EditMode = DataGridViewEditMode.EditOnEnter
Case Else
GridView.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2
End Select
End Sub
Set the DropDownStyle property of your combo box to DropDownList...
Perhaps old.. But make sure to set ReadOnly property to false, else the cell wont enter editmode and therefore the EditingControl returns null and casting DroppedDown = true will cast a NullReferencException.