|
that's so i don't know how should i do that.
my Id field is numeric and i don't want to convert to string but i can't find any more way.
may i ask a help?
|
|
|
|
|
So don't convert to a string.
Like I said, set a breakpoint... You need to learn how to debug, or you'll be on here every day asking for more help.
And don't use the "var" keyword until you REALLY know what you're doing. It leads to bad habits.
|
|
|
|
|
Hi All,
I'm stuck on this particular issue. I have a custom combobox that is to be used with various generic collections of different types. Inside this control it needs to automatically update a database table with new values and then add and select them to the underlying collection.
If I use the Items.Add() method it blows up with "Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead."
The problem I'm facing is how to cast the ItemsSource so that I can actually add the item and then set is as the selected item.
Any ideas?
TIA,
|
|
|
|
|
I think you have to unbind the ItemsSource property, modify the collection, and then rebind.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Just cast it as an IList, or an ICollection if necessary. All of the generic lists implement the non-generic interfaces. Just make sure you're adding an item of the correct type.
|
|
|
|
|
Thanks for the replies guys ...
|
|
|
|
|
It's exactly what the error message says... Your ItemsControl is bound to a Collection or View which serves as source for data. Once this (apparently one-way-from source) binding is estabilished, you cannot add items directly, you have to use the ItemsSource...
|
|
|
|
|
Hi
I have one query as
Consider i have ICheck interface which is implemented by class "Data".
So I can access functions in Class Data using
Code as
1)
Data obj;
obj.Fun();
2) ICheck ck = new Data();
ck.Fun()
So what is advantages of using second code.
|
|
|
|
|
You can implement the ICheck interface in any class/struct you like. You can then use the same method an any instances of any of those classes.
|
|
|
|
|
You can only derive a class from a single other class.
For example
public partial class frmMain : Form
{
...
}
But you can inherit as many Interfaces as you need.
For example
public partial class frmMain : Form, ICloneable, IComparable, IDisposable
{
...
}
(Not that I am suggesting that is a sensible Interface list for a form, it's just an example)
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
In your example, there's very little advantage. Where the use of the interface comes into its own is when you want to perform a specific method, e.g. Dispose an object. Rather than having to use reflection to determine whether or not an object contains that method, you can use the interface to do the action. Consider the following snippet:
Data obj = new Data();
ICheck check = obj as ICheck;
if (check != null)
check.Fun(); Now, if Data doesn't implement this interface, the code still compiles and behaves as you'd expect. This really comes into its own if you are using something like Inversion of Control where you'd use the interface to retrieve the object, e.g.:
ICheck obj = MyIocContainer.Resolve(
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Onyx
modified on Saturday, September 11, 2010 8:14 AM
|
|
|
|
|
Pete O'Hanlon wrote: Now, if Data doesn't implement this interface, the code still compiles and behaves as you'd expect.
Oh my god, no! If Data does not implement ICheck the code would not compile, at least in the statically typed polymorphic world!
|
|
|
|
|
I checked the code I typed in and realised I'd forgotten to put as ICheck on the relevant line. I've amended it, and the code works exactly as I described. Thanks for bringing this to my attention.
|
|
|
|
|
Very little with a local variable -- very much with a parameter or property.
|
|
|
|
|
An important one - the using () pattern wouldn't work without the use of IDisposable .
|
|
|
|
|
Go and google for Dependency inversion. Basically, you use interfaces to loosen dependencies between components. Consider:
public class Data : IData {
private IDataChecker mDataChecker;
public Data(IDataChecker pDataChecker) {
mDataChecker = pDataChecker;
}
}
Your concrete Data depends only on IDataChecker interface, not on its implementation. The consequence is that you can use many different implementations of IDataChecker without changing Data .
|
|
|
|
|
I've written multithreaded code using MFC and understand that well. I'm working on a C# code in which I want to fill in an ArrayList with some data, using a separate thread, and then use the ArrayList data to populate a ListBox on my Form.
Can someone point me to a good example of how to pass data back from a thread in C#? I've found some examples using BackgroundWorker ..., but I'm not sure if that is the only way, or the best way, etc. None of my C# books have anything but very simple threading examples.
Thanks,
Tom
|
|
|
|
|
This article[^] will tell you how your thread can access the GUI parts. And yes a BackgroundWorker often is the best way to achieve this.
|
|
|
|
|
I'm new to online forums discussion, but I try to be clear.
I'm developing a basic conversion from VB to C#. This portion of the code is a user input, ex..inter a number click - print out Is it a number: true or Is it a number: false.
If user input anything other than a number, print out will be Is it a number: false
I have coverted, but getting error: Return error "expected class, delegae, enum, interface, or struct"
I have a red line under void.
I tried the web site that was mentioned on a similar question, but still got red line under void.
Protected Sub btnStep2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim bTest As Boolean
Dim iNum As Integer
'Integer.TryParse is used to see if the compiler can convert
' the string to an Integer
' It returns a Boolean and if successful
' iNum will hold the numeric result.
bTest = Integer.TryParse(txtStep2.Text, iNum)
lblData.Text = "Is it a number: " & bTest.ToString()
End Sub
protected void btnStep2_Click(object sender , System.EventArgs e )
bool bTest = false;
int iNum = Integer;
{
bTest = Integer.TryParse(txtStep2.Text, iNum);
lblData.Text = "Is it a number: " & bTest.ToString();
}
modified on Wednesday, September 8, 2010 11:58 PM
|
|
|
|
|
1.
I don't see any question. Do you have one?
If there are compile errors or run-time exceptions, you should post them, and indicate what line they apply to.
2.
please use PRE tags when publishing multi-line code snippets, they improve readability, and hence the quality of the replies.
3.
TryParse works at run-time, it does not help the compiler at all.
4.
I think it is int.TryParse(...) .
Furthermore the method returns a boolean flag to indicate result; only when true is returned, the parsing succeeded, so you should not claim "It is a number" when false gets returned.
|
|
|
|
|
Your opening braces are two lines too low.
|
|
|
|
|
A few things are wrong here. First of all, you are trying to declare two variables, bTest and iNum, outside of the method body... you can't do that. Put them inside the curly braces. Second, you are trying to initialize iNum to "Integer", which is a datatype, not a value; that will not work. Instead, assign it a value (e.g., 0). Third, I'm pretty sure TryParse expects the second parameter to be passed either by reference or as an output variable. In C#, you must explicity indicate that, as with this example:
Integer.TryParse("0", ref iNum);
|
|
|
|
|
I try to hide/show panels with controls depending on what TreeView node the user clicks (for large data inputs), but it doesn't work and I have no idea why not.
This is my code for the TreeView's AfterSelect event:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
{
if (treeView1.SelectedNode == null)
{
this.Text = "null";
}
else
{
if (treeView1.SelectedNode.Name == "Node1")
{
panel2.Visible = false;
panel1.Visible = true;
this.Text = "panel1 + | panel2 -";
}
else if (treeView1.SelectedNode.Name == "Node2")
{
panel1.Visible = false;
panel2.Visible = true;
this.Text = "panel1 - | panel2 +";
}
}
}
By changing the form text I confirmed that the event gets properly thrown and by stepping through the code I found out that if Node2 is selected, the panel2.Visible = true line does absolutely nothing and afterwards Visible is still false .
Why does that happen? I'm really confused.
Thanks.
|
|
|
|
|
I created a test project with a TreeView, some Nodes, and two Panels; your code works fine for me.
|
|
|
|
|
This stuff would work just fine, provided the controls and panels are layed out properly.
|
|
|
|