|
mObj is declared in the XAML, so in code, you need to retrieve the instance that's in the resources, instead of creating a new one. As I say I can't remember what the expression is exactly. It's something like mObj = Page.Resources["mObj"] but I know it isn't that simple. Someone who works with this stuff on a regular basis should come around here in a little while.
|
|
|
|
|
Thanks, realy
I have solved it:
private void button1_Click(object sender, RoutedEventArgs e)
{
CMyData mObj = (CMyData) dockPanel1.FindResource("myDataObj");
mObj.pText = "Hello\r\nWorld";
}
|
|
|
|
|
The reason this isn't working is pretty simple. You haven't actually hooked mObj in to your DataContext anywhere. All you need to do is enter the following after you initialise mObj:
DataContext = mObj;
|
|
|
|
|
but I have
<TextBox.Text>
<Binding Source="{StaticResource mObj}" Path="pText" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" />
</TextBox.Text>
msdn:
Using the DataContext property on a parent element is useful when you are binding multiple properties to the same source. However, sometimes it may be more appropriate to specify the binding source on individual binding declarations. For the previous example, instead of using the DataContext property, you can specify the binding source by setting the Source property directly on the binding declaration of the button, as in the following example:
above
Now it works
|
|
|
|
|
But the mObj in your XAML is not the mObj in the code behind. Just because they share a name, does not mean they are the same.
|
|
|
|
|
Hello,
i am abeginer so how to start C#.
|
|
|
|
|
|
.NET Book Zero[^] is a great free introduction.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
hello guys...Recently I cam across a requirement in which I have to get the PK Key values back, of the inserted / updated rows. For example
<pre lang="c#">
try
{
connection.Open();
// no of rows affacted
int AffactedRows = command.ExecuteNonQuery("Some Insert Query Here", connection);
connection.Close();
MessageBox.Show(result.ToString() + " Row(s) Inserted");
}
catch(Exception ex)
{
connection.Close();
MessageBox.Show(ex.Message);
}
</pre>
Now you see <b>AffactedRows</b> contains the number of affected (or inserted) rows. Now how do I get IDs of these inserted rows? thnx for any help or pointers 
|
|
|
|
|
This almost belongs in the database forum.
It is up to your some insert query to return the value generated by the identity field. Either as an out parameter or as the return value or the selected record just inserted.
I used stored procedures that return the inserted record using the SCOPE_IDENTITY()
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
For a single row insert you can do a multipart query, like
update MyTable insert (a, b, c) values (1, 'Two', 2012-01-03); select SCOPE_IDENTITY();
... and then ExecuteScalar will return the key value added for that row.
There is a way to get the values back from a bulk insert but I can't remember what it is (I was too lazy to write the logic behind a bulk insert/update save procedure and just do a one line query for each item to be saved, considering there were only 50 or so at most in the application this was for).
Edit: SCOPE_IDENTITY is the SQL Server version, if you're using another database then you'll have to use something else, but I think they all have an equivalent query you can run.
|
|
|
|
|
I suspect my mentor is attempting to reduce me to girlie tears. I am to take my basic multiplication code and restrict the number of characters a user can enter (in order to avoid an overload)
After searching stackoverflow and Google, I can only find tutorials for textboxes but not working with console applications...or am I simply dim (stop laughing).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace debprojectC
{
class Program
{
static void Main(string[] args)
{
int number1, number2;
Console.WriteLine("Please enter a number:");
number1 = Int32.Parse(Console.ReadLine());
Console.WriteLine("Please enter another number:");
number2 = Int32.Parse(Console.ReadLine());
int result;
result = number1 * number2;
Console.WriteLine("Multiplication:" + result.ToString());
Console.ReadKey();
}
}
}
Assistance please.
Deborah
|
|
|
|
|
Instead of using Console.ReadLine you are going to have to use Console.ReadKey. Something along the lines of this:-
string str = string.Empty;
while (str.Length <= 5)
{
char c = Console.ReadKey(true).KeyChar;
if (c == '\r')
{
break;
}
if (c == '\b')
{
if (str != string.Empty)
{
str = str.Substring(0, str.Length - 1);
Console.Write("\b \b");
}
}
int enteredValue;
if(Int32.TryParse(c.ToString(), out enteredValue))
{
Console.Write(c);
str += c;
}
}
Console.WriteLine();
Console.WriteLine("You entered " + str);
Console.ReadLine();
This checks if the char entered is numeric, it handles backspaces and it checks to see if the user pressed enter. I am sure you could alter this to work with your app.
Hope it helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Thank you so much. This helps a great deal.
|
|
|
|
|
Glad to help
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
An alternative way to avoid the overload is just to check that the parsing actually succeeded:
bool MultiplyFromConsole(){
int number1, number2;
string line1, line2;
Console.Write("Please enter a number: ");
line1 = Console.ReadLine();
Console.Write("Please enter a number: ");
line2 = Console.ReadLine();
if(!(int.TryParse(line1, out number1) && int.TryParse(line2, out number2))
return false;
Console.WriteLine("Multiplication: " + (number1 * number2));
return true;
}
|
|
|
|
|
Thank you. My mentor wants me to allow the user another chance if he/she enters a number that is too large or enters letters instead of number. This is quite a learning experience.
Thank you for your help.
Deborah
|
|
|
|
|
hi
how to paint lines on combo-box in difference colors ?
for example:
line1 - red
line2 - green
line3 - yellow
i need any c# code
thanks
|
|
|
|
|
Throw us a bone here. What technology?
|
|
|
|
|
on WinForm , FrameWork 3.5 , C#
thanks
|
|
|
|
|
ComboBox and ListBox offer the same technique for OwnerDrawn painting; you can find an example here[^].
|
|
|
|
|
- Set Combo's draw mode (property is called DrawMode or something similar) to OwnerDrawFixed.
- Write OnPaint handler that paints the current item's background, if you want that
... and uses a brush of the appropriate colour to paint the text. Use the Font property of the combo.
|
|
|
|
|
i want to learn .net i have no idea please help me out
|
|
|
|
|
Decide which language you want to use.
Download the free tool from Microsoft Visual Studio express
Locate a good book and start working through it.
Never underestimate the power of human stupidity
RAH
|
|
|
|