|
I have a datagridview with 1200+ names in it. My users want to type in a few letters (in a separate textbox) of a name and jump to the first name starting with these letters. I have a special column named shortname for this purpose.
I've made a dataview with the filter option, and that works but only the names with these letters are shown. What my users want is the complete list (sorted by short name), and the first occurance of the search letters selected.
can anybody point me in the right direction ?
I'm using C#2008
Thanks in advance,
Rob
|
|
|
|
|
What about looping all the datagridview rows with a foreach, checking the desired column for a partial match, if found then get the index of the found row and break the loop. then set the FirstDisplayScrollingRowIndex of the dataGridView to be the index you obtained from the loop
Example?...
int index = -1;
string searchText = textBox1.Text;
foreach(DataGridViewRow row in dataGridView1.Rows)
{
if(row.Cells["shortname"].Value.ToString().StartsWith(searchText))
{
index = row.Index;
break;
}
}
if(index >= 0)
dataGridView1.FirstDisplayScrollingRowIndex = index;
...This code should be put in a TextChanged event handler for the textbox
Actually, in regards to the example code, you can just assign the FirstDisplayScrollingRowIndex propoerty inside the loops if statement and remove the need for the 'index' variable.
Of course, there may be a built in function i dont know about, if you have found a better solution already then please post it
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I was indeed looking for a more elegant solution, but as the data is already on the users computer a bit of number crunching should not take too long, so if no further ideas come up I will use your solution.
Thanks for your time.
Rob
|
|
|
|
|
Hi everyone,
I have a Windows service that I made on my PC here which has Win XP pro on it and it creates some event logs. It runs fine here but now when I'm trying to deploy it on Staging environment where we have Windows Server 2003, it just doesn't run cause it need the administrative rights for it. Can any one tell me how to tackle this situation. Is there a way to impersonate the Windows Service or anything else?
Any help would be greatly appreciated.
Regards,
|
|
|
|
|
Open the configuration screen, and go to the administrative tools. From there, open the "Services" MSC. Find your service in the list, rightclick it and select "Properties". The second tabpage (called Log On) lets you specify the user-account under which the service should run.
Good luck
I are troll
|
|
|
|
|
ahh!! Thanks man, that was beautiful.
|
|
|
|
|
You're welcome, and thanks for the kind words
I are troll
|
|
|
|
|
Hi, Everybody.
I'm a newbie in C# and I need all your suggestion, advice or script about below script.
I have a class function called FormAction() as below that will keep all the form called. When I have more forms, then I need to do same calling method.
private void FormAction(FormName)
{
switch(FormName)
{
case "frmGUI1":
frmGUI1 lfrm1 = (frmGUI1)Application.OpenForms(FormName);
lfrm1.Show();
break;
case "frmGUI2":
frmGUI2 lfrm2 = (frmGUI2)Application.OpenForms(FormName);
lfrm2.Show();
break;
case "frmGUI3":
frmGUI3 lfrm3 = (frmGUI3)Application.OpenForms(FormName);
lfrm3.Show();
break;
}
}
Can I just code in little line to perform called form? If can, can you give me examples or how to code it.
Thank for your help.
RoalearK
|
|
|
|
|
frmGUI1, frmGUI2 and frmGUI3 all derive from Form. Instead of the switch statement, cast Application.OpenForms(FormName) to a Form, and then call the Show method. So it would look like this:
private void FormAction(string FormName)
{
Form frm = Application.OpenForms(FormName) as Form;
if(frm != null)
frm.Show();
}
|
|
|
|
|
Thank buddy, But I still got some question on that.
How about I need to use that particular form function? For example below, frmGUI1, I need to call save function and frmGUI2, I need to call on Delete function.
If I use to that code cast to a Form frm = Application.OpenForms(FormName) as Form, am I can't to use particular form function?
private void FormAction(string FormName)
{
switch (FormName)
{
case "frmGUI1":
frmGUI1 lFrmGUI1 = (frmGUI1)Application.OpenForms(FormName);
lFrmGUI1.Save();
break;
case "frmGUI2":
frmGUI2 lFrmGUI2 = (frmGUI2)Application.OpenForms(FormName);
lFrmGUI2.Delete();
break;
}
}
Anyway, thank for your help.
RoalearK
|
|
|
|
|
Am a newbie to .net so please can anyone help me out how to print only datagridview in a form with print preview option using C#.Net.
|
|
|
|
|
pradeepc_mca wrote: Am a newbie to .net so please can anyone help me out how to print only datagridview in a form with print preview option using C#.Net
Ref
cheers,
Abhijit
CodeProject MVP
|
|
|
|
|
I'm currently testing several ways to have one application get hold of an object from another application. Both are written in C# and wether I use IPC channels or WCF Service Contracts I end up with the same problem. If I use a simple class whose properties and methods only return the built in types (such as int, string or ArrayList) it works fine, but if I add another property of a custom made type I get an error. IPC gives me a InvalidCastException and WCF puts the channel in a Faulted state and it breaks. Obviously I'm doing something wrong and I hope someone can give me a hand. The server looks like this:
public interface IBase {
int IntTest { get; }
String StringTest { get; }
IOther OtherTest { get; }
String Test(String txt);
IOther Test3();
}
public interface IOther {
String StringTest { get; }
String Test(String txt);
}
public class Base : MarshalByRefObject, IBase {
public int IntTest {
get { return 4; }
}
public string StringTest {
get { return "A string from Base"; }
}
public IOther OtherTest {
get { return new Other(); }
}
public string Test(string txt) {
return "Base called with: " + txt;
}
public IOther Test3() {
return new Other();
}
}
public class Other : MarshalByRefObject, IOther {
public string StringTest {
get { return "A string from Other"; }
}
public string Test(string txt) {
return "Other method called with: " + txt;
}
}
The server is registered like this:
public MainWindow() {
InitializeComponent();
IpcChannel ipcCh = new IpcChannel("IPChannelName");
ChannelServices.RegisterChannel(ipcCh, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Base), "CName", WellKnownObjectMode.Singleton);
}
The client looks something like this:
IpcChannel ipcCh = new IpcChannel("myClient");
ChannelServices.RegisterChannel(ipcCh, false);
obj = (IBase)Activator.GetObject(typeof(IBase), "ipc://IPChannelName/CName");
Console.WriteLine("Returns: " + obj.Test("a text"));
Console.WriteLine("Returns: " + obj.StringTest + " " + obj.StringTest.Length);
Console.WriteLine("Returns: " + obj.IntTest);
Console.WriteLine(obj.OtherTest.ToString());
The last line gives me the InvalidCastException or, in the cae of WCF, the Faulted pipe. Please help.
|
|
|
|
|
Hi,
this may seem silly but it looks as if you've put the interfaces in the *server* application. This is certainly possible, but would require the client to have a reference to the server. Normally one doesn't want to deploy the server on the client machine so one would put the interfaces in a common assembly to be deployed on both client and server.
That said, if you have duplicated the interface declarations so that the code exists in both client and server assemblies then that is your problem - and it should indeed result in InvalidTypeCastException .
|
|
|
|
|
Hi and thanks for replying,
I have indeed duplicated the interface declaration in the client app. I put the interface in a shared assembly instead and that removed the InvalidCastException. Unfortunately it now wants the object to derive from MarshalByRefObject. As far as I can tell my remote able object does that already, as well as implement the IBase and IOther interfaces respectively. I don't have to put the implementation classes in the shared assembly as well, do I?
Actually, I just tried that but I still get the same RemotingException.
|
|
|
|
|
Hi again,
You should be able to use remoting regardless of whether you derive from MarshalByRefObject , though objects not so derived would be marshalled by value. In other words, if you instantiate such a "remote" object it would be binary serialized at the server, sent to the client, and deserialized there. In other words the object would live on the client and not really be a remote object at all. (However this technique can be used to allow a server to basically ship an implementation to the client.)
And you don't need the implementation to be in a common assembly.
It would be nice to know what the exception message you're getting is. And better yet if you could post the absolute minimum of code required to reproduce the problem.
|
|
|
|
|
I switched to WCF but still can't get it to work. Here is what my code looks like now:
The interface looks like this:
[ServiceContract]
public interface IBase {
int IntTest {
[OperationContract]
get;
}
String StringTest {
[OperationContract]
get;
}
IOther OtherTest {
[OperationContract]
get;
}
}
[ServiceContract]
public interface IOther {
String StringTest {
[OperationContract]
get;
}
}
It is implemented in both projects. I tried using a shared assembly but get the same result. My server now looks like this:
public partial class MainWindow : Window {
private Base fb;
private ServiceHost host;
public MainWindow() {
InitializeComponent();
fb = new Base();
host = new ServiceHost(fb, new Uri[] { new Uri("net.pipe://localhost") });
host.AddServiceEndpoint(typeof(IBase), new NetNamedPipeBinding(), "PipeReverse");
host.Open();
}
private void Window_Closing(object sender, CancelEventArgs e) {
host.Close();
}
}
And here is my implementation of the interface:
[Serializable]
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class Base : MarshalByRefObject, IBase {
public int IntTest {
get { return 4; }
}
public string StringTest {
get { return "A string from Base"; }
}
public IOther OtherTest {
get { return new Other(); }
}
}
[Serializable]
[DataContract]
public class Other : MarshalByRefObject, IOther {
[DataMember]
public string StringTest {
get { return "A string from Other"; }
}
}
The client looks like this:
public partial class Form1 : Form {
IBase obj;
public Form1() {
InitializeComponent();
ChannelFactory<IBase> pipeFactory =
new ChannelFactory<IBase>(
new NetNamedPipeBinding(),
new EndpointAddress(
"net.pipe://localhost/PipeReverse"));
obj = pipeFactory.CreateChannel();
}
private void button2_Click(object sender, EventArgs e) {
Console.WriteLine("Returns: " + obj.StringTest + " " + obj.StringTest.Length);
Console.WriteLine("Returns: " + obj.IntTest);
Console.WriteLine(obj.OtherTest);
}
}
Everything works like a charm except this line:
Console.WriteLine(obj.OtherTest);
It give me a CommunicationException with the message "There was an error reading from the pipe: Unrecognized error 109". As far as I can tell that is a broken pipe due to a faulted state but I can't figure out why. Any ideas?
A thanks for helping out, I'm getting so frustrated with this...
|
|
|
|
|
Hi All,
There is an interesting Article "Nav Autoupdate with c#" under Library section
Link:
http://www.codeproject.com/KB/library/AutoupateNAV.aspx
Thanks
|
|
|
|
|
Hi,
I am required to implement the reload process for display updated data if database has been changed by other user in Windows Forms, dose anyone has similar exp for share?
I am planned to use the polling method but dose it contain alternative solution?
Thanks.
|
|
|
|
|
What is your database, SQL 2005 has some extended functionality to support the but it is not simple.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
the target database should be mssql 2k, so dose it support this function?
|
|
|
|
|
Hi,
there is an alternative solution to polling. The technique itself is based on the observer pattern. The model (database etc.) informs all before registered listeners about a change in the model. The listener itself can then react accordingly.
You have two options to implement this:
1) Some database-server can inform registered applications (through the connection) about changes in the database. Check if you DBMS can do this (look for event or sth. similar).
2) Implement a layer which communicates between different hosts. Then use this layer to send a message to all registered applications that you performed a database change. (You should avoid using this solution. Better use your polling mechanism)
Hope this helps.
Regards
Sebastian
|
|
|
|
|
1. The target database should be mssql 2k, so dose it contain an event for supporting this feature? or any keyword can help for search? I don't know what kind of term can be used for this "feature".
2. New layer for communication should not work if my target is 2 tier (client program and mssql database), so I don't know where should place the layer if without server application.
Thanks~
|
|
|
|
|
FYI, I've read on and noticed you need this to work with MSSQL Server 2000.
You've said little about your scenario so it's a bit tricky to give any advice. So this is just some general info instead.
The database does not provide anything that makes it directly easy to provide an event in your application. It is possible though. One way is to write an extended stored procedure in C++ that notifies your application (for example using a message queue) that the update has taken place, and then call this from a trigger in the database.
Another option is available if the database is (supposed to be) accessed only via your client app and you can update all installed clients before the feature becomes (fully) functional. In this case you could use remoting or message queues or web services or even sockets (if you like to needlessly complicate things and reinvent the wheel ) to notify all clients when any client has just modified the data in question.
To be honest, I think polling is a better option. Just remember that if you've got loads of clients and poll frequently it will generate considerable load on the database and it may be smart to put a caching server in the middle. 500 clients polling every 5 seconds is 100 requests per second. If you've got such a case, consider making an app that polls the db every 5 seconds and updates a cached value (such as a timestamp). Then clients can poll this app (which of course responds based on the cached information) without having to acquire shared locks in the database and the rest of the overhead of executing some query a hundred times per second.
|
|
|
|
|
Hello I want to draw a text along an array of Points
Any suggestion for a good approach ?
Thanks for any help
|
|
|
|