|
I'm hoping that someone could give me some advice on how to code a data-grid so that the first row added appears at the bottom, and each additional row fills in above the previous!
In the program I am building, the data-grid starts out empty, and then the user adds information over the course of the session - the first piece of information he adds needs to be on the bottom, and then the second on top of the first, etc.
Any advice appreciated !
Dave
|
|
|
|
|
I've got one of those fancy rotating screens, so all I do is rotate it 180 deg, mind you it's tough on the neck
Sorry, could not resist.
There are a number of solutions, depending on your data source. If you are manually creating the rows then there should be a DGV.Row.Insert(index) obviously 0
If your data is set based (datatable or list) then you need to insert it into the appropriate postion in the supporting datasource.
Either way you are going to have to manage the DGV manually rahter than changing a setting or two!.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hmmm. I tried the command you recommended, and Visual Studio rejected the syntax. Any idea what I could be doing wrong?
I created a DataGridView object on the form and called it DG1.
I created a button. For the onclick event in the button, I went to type the command DG1.Row.Insert(0) and it rejected the syntax.
Dave
|
|
|
|
|
So I was typing from memory, did you take a look around to get the correct syntax. I will feed you ideas, you have to do the work. I have no interest in providing code, thats what articles are for.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I did scroll through all of the possible commands for the object, and none of them seemed relevant.
|
|
|
|
|
I am a novice of C#,Could you please tell me the advantage and disadvantage of using interface and not using interface in the proggram? I'm gragteful if you give a litte code for contrast. Thanks!
|
|
|
|
|
Well, a program without an interface can't really do much, can it ? Or do you mean interfaces as a coding construct, not a user interface ? I would suggest you buy a book on C# and read it, rather than hope to get a deep understanding from random forum replies.
An interface is useful mostly as a means to get around the lack of multiple inheritance.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
I'm assuming like Christian that your question is about using interfaces in your own classes. Interfaces do not offer any significant performance benefit. However, they are very useful in situations where classes do inherit from the same base type. Here's a quick example of using interfaces:
public class SecretService : ISecurityCleared
....
public class CIA : ISecurityCleared
...
public class President : ISecurityCleared
...
//ISecurityCleared interface...
public interface ISecurityCleared
{
void ViewTopSecretMessage(string message);
}
//sample code...
private void TopSecretMessage(string topsecretmessage)
{
List<ISecurityCleared> securityCleared = new List<ISecurityCleared>();
securityCleared.Add(new SecretService());
securityCleared.Add(new CIA());
securityCleared.Add(new President());
for (int i = 0; i < securityCleared.Count; i++)
securityCleared.ViewTopSecretMessage(topsecretmessage);
}
Again, no performance increase, just cleaner code without having to worry about inheritance issues.
Cheers,
Richard
There cannot be a crisis today; my schedule is already full.
|
|
|
|
|
Richard Blythe wrote: securityCleared.Add(new President());
I wish...
|
|
|
|
|
No comment
There cannot be a crisis today; my schedule is already full.
|
|
|
|
|
Another advantage of interfaces (again assuming you are talking about code constructs and not the UI) is that they provide a well defined contract to program against. In other words, if you know that a certain type supports a certain interface, then you know that it implements the methods on that interface. An example:
public interface IMyInterface
{
void DoSomething();
}
public class MyInterfaceClass : IMyInterface
{
public void DoSomething()
{
Console.WriteLine("IMyInterface called");
}
} Then, you could do something like the following:
public class MyGenericClass<T> where T : IMyInterface, new()
{
public void CallAMethod()
{
T value = new T();
value.DoSomething();
}
} The generic class is constrained to using classes that support the IMyInterface interface, which means you could write code like this:
new MyGenericClass<MyInterfaceClass>().CallAMethod();
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Another benefit of interfaces is that they help with code reuse.
If a method parameter is an interface type, you can call it by passing an object of ANY class that implements that interface.
|
|
|
|
|
thanks all for your help!
|
|
|
|
|
look at this situation(this is just an example for clarification):
i have 2 threads:
thread1: is my main thread,( the static Program class) and should for example Run a form.
thread2: is my sec thread and should show a Splash screen that should be displayed according to my main thread.
thread1(main) wants to update a progressbar on thread2. i am a little confused...
my solution:
i guess that i could solve this by implementing events, rising them on thread1 and Handling them on thread2 and do the requested job accordingly(i.e. updating a progress).
but sth new arises and that was Cross-Thread-Oper... , and there is no Invoke Metod for my this obj (that is Static Program class, don't call me stupid) to prevent this exception(cross-thread-...excption).
|
|
|
|
|
Have you tried progressbar.Invoke ?
|
|
|
|
|
Thread1 should call Invoke/BeginInvoke on the progressBar in Thread2.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I know the Invoke procedure, but we can use Invoke when we have a Form!(Form.Invoke())
my threads are implemented in Program class where i Run my application(and there is no this.Invoke method!):
look here: my Form1 obj(f) during its lifetime will raise some events! i want to handle those events from thread2 and do the jobs in thread2!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Server
{
static class Program
{
static System.Threading.Thread thread2 = null;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Form1 f = new Form1();
thread2 = new System.Threading.Thread(new System.Threading.ThreadStart(worker));
thread2.IsBackground = true;
thread2.ApartmentState = System.Threading.ApartmentState.STA;
thread2.Start();
try
{
f.job1 += new EventHandler(Job1);
f.job2 += new EventHandler(Job2;
f.job3 += new EventHandler(Job3);
Application.Run(f);
}
catch(Exception r)
{
}
}
static void worker()
{
}
}
|
|
|
|
|
Someone has asked a similar question to yours, here[^], perhaps you can get some ideas from there.
There are also several articles here on CodeProject. Use the Search articles box, at the top of the page, and search for threaded splash screen, or similar.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Does the worker() method create a Form? What do the event handlers for Job1, Job2 and Job3 do - update the form created inside worker?
If you're getting a CrossThread exception, it means you're updating *some* UI control from the wrong thread - it doesn't necessary have to be the main Form.
|
|
|
|
|
In general speaking, i want to handle events that raise by thread1 and process them with thread2, that's all!
|
|
|
|
|
My first thought is a synchronized queue of delegates (which represent fired events) but that would be painful and probably overkill.. It's just a thought, not advice.
|
|
|
|
|
Hi.
My solution (working in VS 2008) has a C# console app, and a C# web service. The service has an entity data model. It has numerous stored procedures. For one of the stored procs, which just returns data (SELECT blah blah FROM...), I added a function import called "Iservice." I saved all, then in my console app, updated the service reference to my C# service. Now, in my console app, I am trying to do the following:
myEnts db = new myEnts(new Uri("http://localhost:3811/isr.svc"));
foreach(st_service sr in db.Iservice(false))
Console.WriteLine("Number#: {0} " + sr.num);
This doesn't work. "Iservice" is the name of the function import I created and I can see it in the object browser, but when I look at the service reference, I can't see it in the object browser. The compiler doesn't like "db.Iservice(false)" and the message is that myEnts from the service reference does not containt a definition for "Iservice."
So when I am in the service project, and look at the object browser, I can see Iservice - however when I look at the service reference in the object browser, from the console project, I do not see Iservice. How come this happens? How can I fix this? I tried saving, closing, and reloading MSVS2008, I tried updating the service reference multiple times. I googled for examples of calling stored procs in the EDM, and tried different ways of calling it as shown here:
http://blogs.microsoft.co.il/blogs/gilf/archive/2009/03/13/mapping-stored-procedure-results-to-a-custom-entity-in-entity-framework.aspx[^]
http://blogs.msdn.com/bags/archive/2009/03/13/entity-framework-modeling-select-stored-procedures.aspx[^]
http://blogs.msdn.com/adonet/archive/2007/09/14/how-to-map-stored-procedures-using-the-ado-net-entity-framework.aspx[^]
I'd appreciate any help.
PS -- The stored proc that I created a function import for takes in a BIT as a parameter. When in my service project, and looking at the object browser, it shows Iservice as "Iservice(bool?)" which is strange to me. Why the question mark?
|
|
|
|
|
dfn wrote: "Iservice(bool?)" which is strange to me. Why the question mark?
I think that it is treating it as nullable.
Apart from that, I am lost.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: I am lost
Have a break. You probably have just exhausted your brain cell with a though FLP problem.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
lol. My brain could use a break from it too you know, or a hint.
|
|
|
|