|
Try
protected void Button1_Click(object sender, EventArgs e)
{
DatesInOrderTextBox.Text = "Dates in order are: " + TextBox1.Text + ", " + TextBox2.Text + ", " + TextBox3.Text;
}
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
ahh thats great thanks for the reply
|
|
|
|
|
how to memorise such a big .netframework?is there any methode?
|
|
|
|
|
Yes, it's called "studying". Perhaps you've learned the technique in school??
|
|
|
|
|
You do not "memorize" it, it's too big - and by the time you know it by heart, there'll be a new version. You'd learn how to use it; once you worked through a C#-book, you should be able to use the documentation[^].
|
|
|
|
|
I agree with this.
I'd add that when I started out I invested in a copy of the Base Class Library text (it was c# 2005 at the time). That was a great book for showing me a great, useful slice of the framework, how it works, and what it can do.
Once you get in the 'mindset' of the framework, how it goes about things etc. You can, more often than not, predict where in the documentation you'll need to look to solve your problem.
|
|
|
|
|
I doubt how much storage capacity you had to memorize the entire .Net framework . Its a bad idea too and save your time doing other interesting stuffs rather running behind memorizing .net framework.
you better store in stack - use it throw it.
Jibesh.V.P
India
|
|
|
|
|
Hey guys so im attempting to throw a project together to increase my knowledge of MVC3 but I have hit a wall...
So from my HolidaysController inside my index 'view' I have created a hyperlink which will navigate the user to the 'create3' ActionResult
@Html.ActionLink("Select 3 Dates", "Create3")
-------------------
In my create3 page I want the user to enter 3 dates into text boxes and when they click 'create' the user will be returned to the previous HolidaysController/Index page
where the dates will be displayed in order of ascending date....ATM I have this working up until the user enters 3 dates and clicks 'create'...However I only know
how to display a message box displaying the order, it is working I just need help getting the order to be displayed from the index page.
Please see my code:
Code for HolidayController/Index:
--------------
[HttpPost]
public ViewResult Index(int HolidayDate)
{
var holidays = db.Holidays.Include("Person");
HolidayList model = new HolidayList();
model.currentPersonID = HolidayDate;
model.PList4DD = db.People.ToList();
model.Categories = holidays.Select(x => new SelectListItem
{
Value = x.Id.ToString(),
Text = x.Person.Name
}
);
int data = HolidayDate;
model.HList4DD = db.Holidays.Where(h => h.PersonId == HolidayDate).ToList();
return View(model);
}
[HttpGet]
public ViewResult Index(string sortOrder, int? currentPersonID)
{
var holidays = db.Holidays.Include("Person");
HolidayList model = new HolidayList();
if (currentPersonID.HasValue)
{
model.currentPersonID = currentPersonID.Value;
}
else
{
model.currentPersonID = 0;
}
model.PList4DD = db.People.ToList();
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "date" : "";
var dates = from d in db.Holidays
where d.PersonId == currentPersonID.Value
select d;
switch (sortOrder)
{
case "date":
dates = dates.OrderBy(p => p.HolidayDate);
break;
}
model.HList4DD = dates.ToList();
return View(model);
}
-----------------------
//View for Index
@*@model IEnumerable<HolidayBookingApp.Models.Holiday>*@
@model HolidayBookingApp.Models.HolidayList
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<p>
@Html.ActionLink("Select 3 Dates", "Create3")
</p>
<table>
<tr>
<th>
PersonId
</th>
<th>
@*HolidayDate*@
@Html.ActionLink("HolidayDate", "Index", new { sortOrder = ViewBag.NameSortParm, currentPersonID = Model.currentPersonID })
</th>
<th></th>
</tr>
<tr>
</tr>
@foreach (var item in Model.HList4DD)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.PersonId)
</td>
<td>
@Html.DisplayFor(modelItem => item.HolidayDate)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>}
<tr>
<div class="editor-label">
@* @Html.LabelFor(model => model.PList4DD, "Person")*@
</div>
<div class="editor-field">
<form action ="/Holidays/Index" id="some" method="post">
@Html.DropDownListFor(model => model.HList4DD.First().HolidayDate, new SelectList(Model.PList4DD, "Id", "Name", Model.currentPersonID), "--select--")
<script>
function updateFormEnabled()
{
if (verifyAdSettings())
{
$('#sbmt').removeAttr('disabled');
}
else
{
$('#sbmt').attr('disabled', 'disabled');
}
}
function verifyAdSettings()
{
if ($('#HolidayDate').val() != '')
{
return true;
}
else
{
return false;
}
}
$('#HolidayDate').change(updateFormEnabled);
</script>
<input type="submit" id= "sbmt" name="ViewHolidaysDD" value="View"/>
</form>
<script>
$('#sbmt').attr('disabled', '');
</script>
</div>
</table>
<br />
<br />
<table>
<div>
Judging by your selection the order of dates are: //HERE IS WHERE I WANT TO DISPLAY THE ORDER OF DATES
</div>
</table>
Just above is where I want to display my dates in order, ascending
------------
-----------------------------------
[HttpGet]
public ActionResult Create3()
{
return View();
}
[HttpPost]
public ActionResult Create3(string date1, string date2, string date3)
{
string FirstDateOrder, SecondDateOrder, ThirdDateOrder;
if (date1.Length > date2.Length && date1.Length > date3.Length)
{
if (date2.Length > date3.Length)
{
FirstDateOrder = date1;
SecondDateOrder = date2;
ThirdDateOrder = date3;
System.Windows.Forms.MessageBox.Show("Order is 1, 2, 3");
return RedirectToAction("Index");
}
else
{
FirstDateOrder = date1;
SecondDateOrder = date3;
ThirdDateOrder = date2;
System.Windows.Forms.MessageBox.Show("Order is 1, 3, 2");
return RedirectToAction("Index");
}
}
if (date2.Length > date1.Length && date2.Length > date3.Length)
{
if (date1.Length > date3.Length)
{
FirstDateOrder = date2;
SecondDateOrder = date1;
ThirdDateOrder = date3;
System.Windows.Forms.MessageBox.Show("Order is 2, 1, 3");
return RedirectToAction("Index");
}
else
{
FirstDateOrder = date2;
SecondDateOrder = date3;
ThirdDateOrder = date1;
System.Windows.Forms.MessageBox.Show("Order is 2, 3, 1");
return RedirectToAction("Index");
}
}
if (date3.Length > date1.Length && date3.Length > date2.Length)
{
if (date1.Length > date2.Length)
{
FirstDateOrder = date3;
SecondDateOrder = date1;
ThirdDateOrder = date2;
System.Windows.Forms.MessageBox.Show("Order is 3, 1, 2");
return RedirectToAction("Index");
}
else
{
FirstDateOrder = date3;
SecondDateOrder = date2;
ThirdDateOrder = date1;
System.Windows.Forms.MessageBox.Show("Order is 3, 2, 1");
return RedirectToAction("Index");
}
}
return RedirectToAction("Index");
}
-----------------------------
--------------
and my view:
@model HolidayBookingApp.Models.Dates
@{
ViewBag.Title = "Create3";
}
<h2>Create3</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Dates</legend>
<div class="editor-label">
@Html.LabelFor(model => model.date1)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.date1)
@Html.ValidationMessageFor(model => model.date1)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.date2)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.date2)
@Html.ValidationMessageFor(model => model.date2)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.date3)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.date3)
@Html.ValidationMessageFor(model => model.date3)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>"Index")
</div>
---------------
Not sure where to go from here something like create a paramter in the Index View which pulls across the order?
Any help would be great thanks guys and sorry about the essay
|
|
|
|
|
Hi,
I'm developing an application that runs in a Windows CE 5.0 environment and I'm using VB.NET in Visual Studio 2008 Pro.
In a Form I have a TabControl with some pages.
My problem is to understand when a page of the TabControl is selected to perform some actions in that page automatically.
In the Compact Framework there isn't the event Control.Enter so I can't use it, that would be the right one...
Does anyone have any idea?
Thanks
|
|
|
|
|
Taking a look at the documentation....
Documentation
Shows us that the Tab Control notifies the PARENT object using WM_Notify messaging.
So you need to look into WM_Notfication messages.
A little more can be found here
Look under Notification section
|
|
|
|
|
Thank you Zaf.
You gave me some useful information.
I honestly do not know well how to use the WM_NOTIFY messages but looking on google I found various information about it, maybe something like this:
Const WM_MESSAGE_TO_MANAGE As Integer = ...
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_MESSAGE_TO_MANAGE Then
End If
MyBase.WndProc(m)
End Sub
In the specific situation I solved my problem in an alternative way (I don't use more different pages of the TabControl but on a single page I add N UserControl and step from one to another with buttons and I use the Click event to do what it takes) but surely this method can be useful to me on other occasions so I will look into the subject.
Thank you very much.
|
|
|
|
|
Hello Steve,
I came across the WM_NOTIFY message and (inter?) windows messaging in the REBAR control (ribbon/taskbar) manipulation code sample on the microsoft website which also provided me with a sample implementation that i found understandable, during the time when i was learning microsoft VB5 CCE.
|
|
|
|
|
Hi,
perhaps the subject is not so explanatory but now I try to explain with an example that well represents my problem.
I have a UserControl with two NumericUpDown and a button, then I have a Form1 with a TabControl1 with just one page.
Loading the form I add some pages to the TabControl and I put in every page my UserControl (called "base") in this way:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mypag As TabPage
Dim myuc As base
For i As Int32 = 0 To 10
mypag = New TabPage
myuc = New base
myuc.Parent = mypag
mypag.Text = "Pag" & i.ToString
mypag.Name = "Pag" & i.ToString
TabControl1.TabPages.Insert(1 + i, mypag)
Next
End Sub
End Class
Than with the button on the page of the TabControl I pass to the next page of the TabControl (and this is done) but I also want to put in the first NumericUpDown of the "next page" the sum of the value of the two NumericUpDown in the current page (the one with the button just pressed) and I don't know how to do this.
The code in the button is:
Public Class base
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tmp, id As Int32
tmp = NUD1.Value + NUD2.Value
id = CType(Parent.Parent, TabControl).SelectedIndex
CType(Parent.Parent, TabControl).SelectedIndex += 1
End Sub
End Class
I don't know how to "poit" to the NumericUpDown of a page different from the one in witch I am, even if I can get the index of that page (I think...)
I tryed something like this:
CType(Parent.Parent, TabControl).TabPages(id + 1)
CType(Parent.Parent, TabControl).TabPages(id + 1).NUD1.Value
Can someone give me some advice?
Thanks in advance
|
|
|
|
|
Where are you creating the NumericUpDown controls? At that point, you'd like to keep a reference to it, at class-level.
Public Class Form1: Form
Private n1 as NumericUpDown
Sub New()
n1 = new NumericUpDown
Controls.Add(n1)
End Sub
End Class
|
|
|
|
|
The NumericUpDown controls are in the UserControl I called "base" (together with the button), not in Form1, and I created them in the design mode, not writing the code as in your example.
In Form1 there is the TabControl in witch at runtime I put 10 pages, each one with a copy of "base" inside.
I did this because I needed a series of screens all the same and this was the most convenient way because I had to design only one screen (and also the build is faster).
The final result should be a series of tabbed pages all the same, the user begins to fill in the first, then the second and at that moment some fields on the page are automatically filled with the data entered on the previous page, and so on page after page.
All the controls are in the UserControl so I think I have to manage this mechanism inside the UserControl (perhaps the button to pass to the next page is not the better place to put the code in because the user can go to the next page also by clicking the tab of the page but in the real page there are also other controls I can use like a CheckBox that must be checked to enable the other controls).
My problem is that when the user is in the page N, I don't know how to reach the controls in page N-1 or N+1.
If I simply design 10 pages in the TabControl, all the same, there is no problem because each control on each page is a single object with a unique name so I have no problem to address it, but this is not the most elegant solution..
|
|
|
|
|
steve_9496613 wrote: and I created them in the design mode
Topic title says "created at runtime", not the designer. If you're using the designer then you can give the controls a unique name indeed, and use that - which is the elegant solution; they'd have a reference on the form-level. There's no need to look them up through the "current" tabpage, as far as the form is concerned, all pages exist.
steve_9496613 wrote: My problem is that when the user is in the page N, I don't know how to reach the controls in page N-1 or N+1.
The same as you reach the tabpage;
NumericUpDown1.Value = 1
|
|
|
|
|
Sorry, I was not able to explain clearly.
Now I try again.
In the designer I create:
1 Form with 1 TabControl with 1 page
1 UserControl with 1 Button and 2 NumericUpDown
(in my first post there is the code of the Form and the code of the UserControl)
At runtime I add 10 pages to the TabControl with a copy of the UserControl in each page.
My problem is in these 10 pages, for this reason I wrote "at runtime" in the topic title.
As you said, I know that if I create all the pages in the designer there is no problem but if I create all the pages at runtime I have to "design" just one page and to write code just for this page (less code I write, fewer errors I do... and then, if I have to change something in the page, I have to change just one page, not 10)
Is there a way to do what I want to do (hoping it is clear what I want to do...)?
|
|
|
|
|
steve_9496613 wrote: In the designer I create:
1 Form with 1 TabControl with 1 page
1 UserControl with 1 Button and 2 NumericUpDown
(in my first post there is the code of the Form and the code of the UserControl)
At runtime I add 10 pages to the TabControl with a copy of the UserControl in each page.
My problem is in these 10 pages, for this reason I wrote "at runtime" in the topic title.
Good explanation
"NUD1", the name-property of the UpDown control, must be unique within the form. It'll generate a variable with that name, and that's what "NUD1" points to; it's not a property of the tabpage, it's the name of a single control.
Ideally, you'd have your own type of tabpage, but I don't know whether the designer would accept that. Might make it impossible to show the page at all in the designer.
The "easy" way is to loop trough all the controls on the current tabpage. There's a Controls -collection that you'd have to loop through, and check whether that's the control (of type numericupdown) that you're looking for.
Not very elegant at all, is it?
So, I'd suggest putting everything you want on that page in a single UserControl , and make it's values available over properties. That way you can instantiate the same control ten times, and still have all the logic and layout in a single place.
|
|
|
|
|
Thanks for your reply.
Try and try at the end I've found a solution that I'll show you, but I have some questions before.
Eddy Vluggen wrote: "NUD1", the name-property of the UpDown control, must be unique within the form. It'll generate a variable with that name, and that's what "NUD1" points to; it's not a property of the tabpage, it's the name of a single control.
...and that was the problem: I put a NumericUpDown control in a UserControl and I give it an unique name (NUD1). When, at runtime, I create 10 instances of the UserControl, what are the unique names of the 10 NumericUpDown controls originated from NUD1?
If I make the value of the NumericUpDown available over a property like this (if I'm not wrong):
Public Property NUDVal() As Int32
Get
Return NUD1.Value
End Get
Set(ByVal value As Int32)
NUD1.Value = value
End Set
End Property
also this property has a unique name... until the UserControl is one, but when I create 10 instances of the UserControl?
So I thought to lists of objects... and that is my solution.
In the UserControl I created my two NumericUpDown controls at runtime, not in the designer, and I added them to an ArrayList. I also added a CheckBox, in the designer, to use the event "Click" for calculations that serve.
In Form1, the main form, when I create the 10 instances of the UserControl, I also add the ArrayList of controls of every UserControl to another ArrayList declared in the form... here is the code:
Public Class base
Public Objs As ArrayList = New ArrayList
Private n1, n2 As NumericUpDown
Sub New()
Dim pos As Point
InitializeComponent()
n1 = New NumericUpDown
pos.X = 209
pos.Y = 90
n1.Location = pos
Controls.Add(n1)
n2 = New NumericUpDown
pos.X = 209
pos.Y = 132
n2.Location = pos
Controls.Add(n2)
Objs.Add(n1)
Objs.Add(n2)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CType(Parent.Parent, TabControl).SelectedIndex += 1
End Sub
Private Sub CheckBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.Click
Dim val1, val2, id, curid As Int32
id = CType(Parent.Parent, TabControl).SelectedIndex
curid = id - 1
If curid > 0 Then
val1 = CType(CType(Form1.ObjsUC.Item(curid - 1), ArrayList).Item(0), NumericUpDown).Value
val2 = CType(CType(Form1.ObjsUC.Item(curid - 1), ArrayList).Item(1), NumericUpDown).Value
n1.Value = val1 + val2
End If
End Sub
End Class
Public Class Form1
Public ObjsUC As ArrayList = New ArrayList
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mypag As TabPage
Dim myuc As base
For i As Int32 = 0 To 10
mypag = New TabPage
myuc = New base
myuc.Parent = mypag
ObjsUC.Add(myuc.Objs)
mypag.Text = "Pag" & i.ToString
mypag.Name = "Pag" & i.ToString
TabControl1.TabPages.Insert(1 + i, mypag)
Next
End Sub
End Class
In this way all the controls I need are inside a list, and I know what kind of object is every element of the list because I put them in the list, I don't need to loop in the list and check each element.
So in the "Click" event of the CheckBox I can "reach" the values of the NumericUpDown controls of the previous page (or of other pages) pointing to them in the list.
Well... it works... although I have some difficulty in evaluate the elegance of this code...
What do you think about this solution?
And I have another question about the pages of the TabControl, but for this I open another topic...
|
|
|
|
|
steve_9496613 wrote: ...and that was the problem: I put a NumericUpDown control in a UserControl and I give it an unique name (NUD1). When, at runtime, I create 10 instances of the UserControl, what are the unique names of the 10 NumericUpDown controls originated from NUD1?
Good assesment; the others wouldn't have a name.
steve_9496613 wrote: also this property has a unique name... until the UserControl is one, but when I create 10 instances of the UserControl?
You'd have 10 controls without a name (the usercontrol), but with a known property that points to the correct control.
steve_9496613 wrote: Well... it works... although I have some difficulty in evaluate the elegance of this code...
What do you think about this solution?
It'll do; seen the technique before, usually when ex-VB programmers want an "array" of controls. It adds a single pointer to the list for each control, so it's not very resource-intensive.
|
|
|
|
|
Let's assume you have a method similar to this one:
public void SomeMethod(string myParam) {
if (string.IsNullOrEmpty(myParam) {
throw new Exception();
}
}
When writing unit tests do you write tests that cover all of the variations of what could trip the exception?
i.e. one test each where
myParam = null
myParam = string.empty
myParam = " "
Or do you just write one of the above tests?
I tend to write all 3 tests. And, similarly, if a positive integer is required I'll have a test for the integer being 0 and one for it being < 0 since the operators are potentially different.
Just wondered what you guys thought, and if I'm overdoing the testing.
Andrew
"My days of not taking you seriously are certainly coming to a middle."
|
|
|
|
|
What you are "testing" is the IsNullOrEmpty function; I'll test with either one, fully confident that the method will behave as documented. When I test, I test my own code, not the frameworks' methods.
|
|
|
|
|
I guess my thought was that I testing to make sure someone didn't change the actual call to IsNullOrWhiteSpace . In theory a future dev could change my IsNullOrWhiteSpace to IsNullOrEmpty and effectively break the method by allowing it to accept an string of whitespace.
I might be being too much of a control freak though.
|
|
|
|
|
Andrew Stoute wrote: In theory a future dev could change my IsNullOrWhiteSpace to IsNullOrEmpty and effectively break the method by allowing it to accept an string of whitespace.
In that case, the only good test would be to compare the methods' body to the actual source-code you have now.
Don't let people change your code if they don't know what they're doing. Any nitwit could guess that if the method behaves different (translate to 'unexpected') that things will break. On a class-level, this is the L[^] from the SOLID principle. Simplest example; don't throw any exceptions that weren't already in the base-class (as the applications' try..catch constructs will not expect it, and break).
|
|
|
|
|
Andrew Stoute wrote: I might be being too much of a control freak though.
Not at all. The backup to this is documenting that it cannot accept whitespace and you may even rewite the code to strip leading and trailing whitespace characters to defend against it.
|
|
|
|
|