|
ur scenario may be different, but, i used the following method in one of my application.
dgv refers to a DataGridView object
BindingSource bs = new BindingSource();
//u may create a custom data source and then populate it
bs.DataSource = YourDataSource;
dgv.DataSource = bs.DataSource;
bs.Position = bs.Find("PropertyToBeSearchedIn", "TextToBeSearched");
|
|
|
|
|
Dewald wrote: The problem is that the grid can have several thousand entries and a foreach search might take much too long.
Why do you think so? Have you tried it?
I have a project with a ListView showing an event log where I filter the rows. I changed the filter to look for part of a string (in a rather inefficient way; creating temporary strings for each item), but with 90000 items the time for searching them all is still hardly noticable.
Your only alternatives to looping the data when the user enters the string, is to do the searching beforehand by setting up some kind of tree, where you can find all items containing the character "a", then among those items all items that contain "ab", et.c. It would perhaps take a few seconds to search through all the data, but then it would be fast to find the items in the tree.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Intrigued by the idea of a search trea, I tried to build a simple class that does it:
public class SearchTree<T> {
private class UniqueList<Key> : IEnumerable<Key> {
private Dictionary<Key, byte> _list;
public UniqueList() {
_list = new Dictionary<Key, byte>();
}
public void Add(Key value) {
_list[value] = 1;
}
public Key[] ToArray() {
Key[] result = new Key[_list.Count];
int index = 0;
foreach (Key value in _list.Keys) {
result[index++] = value;
}
return result;
}
public IEnumerator<Key> GetEnumerator() {
return _list.Keys.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
return _list.Keys.GetEnumerator();
}
}
private class NodeList : Dictionary<char, SearchNode> {
public new SearchNode this[char c] {
get {
SearchNode node;
if (!this.TryGetValue(c, out node)) {
node = new SearchNode();
this.Add(c, node);
}
return node;
}
}
}
private class SearchNode : NodeList {
private UniqueList<T> _indexes;
public SearchNode() {
_indexes = new UniqueList<T>();
}
public void Add(string word, int pos, T index) {
_indexes.Add(index);
if (pos < word.Length) {
this[word[pos]].Add(word, pos + 1, index);
}
}
public T[] FindWord(string text) {
if (text.Length == 0) {
return _indexes.ToArray();
} else {
SearchNode node;
if (this.TryGetValue(text[0], out node)) {
return node.FindWord(text.Substring(1));
}
return null;
}
}
}
NodeList _nodes;
public SearchTree() {
_nodes = new NodeList();
}
public void AddWord(string word, T index) {
for (int i = 0; i < word.Length; i++) {
_nodes[word[i]].Add(word, i + 1, index);
}
}
public T[] FindWord(string text) {
if (text.Length > 0) {
return _nodes[text[0]].FindWord(text.Substring(1));
}
return null;
}
}
Creation of a search tree (from the string array lines ):
SearchTree<int> tree = new SearchTree<int>();
for (int i = 0; i < lines.Length; i++) {
foreach (string word in lines[i].Split(' ')) {
tree.AddWord(word, i);
}
}
Usage:
int[] result = tree.FindWord("a");
The result is an array of indexes for the lines where the words were found (or null if nothing was found).
I made some test data by copying text from some articles here, ending up with 3313 lines of text, 22248 words. Creating a tree from this takes around 260 ms on my computer, and searching the tree for a string like "win" gives a result of 31 lines and takes around 0.00076 ms.
The class is quite flexible, you can use most anything as index, you could even use the rows in a grid view: SearchTree<DataGridViewRow> . Searching that tree would give you an array containing the rows where the words were found.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Bookmarked for further use (I can think of plenty of applications) - 5 from me
You should make this into an article.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Excellent idea and thanks for the post. I will definitely try this out in some other projects as well.
As a matter of interest, you were quite right in your original post that an exhaustive search (with something like foreach) really doesn't take as much time as one would have thought. I'm amazed at how quickly it runs through 9000 entries.
Thanks again.
|
|
|
|
|
Why not with a db??? that´s not hard at all, and easier!
Create a textbox_textchanged event and trigger a store procedure from there!!!
I already done it, but with help of a db.
|
|
|
|
|
Hi
I want to write a windows application that doesn’t have a form, that is no input or output.
I have tried the console project but that causes a CMD box to flash up, I have tried the windows service option but this doesn’t allow it to be run from the command line.
This is what I want to do:
My application will be launched from a function key in our main application (uses Shellexecute) it then checks some items and launches another existing application.
no user interaction is required.
|
|
|
|
|
use the "main" method
do not show any form (if u have any)
|
|
|
|
|
you can hide the form on start up
< note this will show the application in taskbar >
private void Form1_Load(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
}
Vikas Amin
UNITED STATES STEEL CORPORATION
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
If you want to hide the window
ShowInTaskbar = false;
Vikas Amin
UNITED STATES STEEL CORPORATION
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
Hi,
I am running a DOS command from my C# application using Process.Start(cmd, arg)
Does it a way to get the result of this command like "Timeout occurred", "File not found" etc...
Thanks.
|
|
|
|
|
If u just need to get an result from a Commnad (ie dir ) then
use ">" so the output wil be directed to text file
c:\ dir > c:\vikas.txt
A tool clip.exe from microsoft does the same and puts the data on the Windows clipboard.
you can also redirect your otput to screeen
stream = freopen("file.txt", "w", stdout)
http://support.microsoft.com/kb/58667[^]
Vikas Amin
UNITED STATES STEEL CORPORATION
My First Article on CP" Virtual Serial Port "[^]
modified on Monday, August 4, 2008 2:48 PM
|
|
|
|
|
you can do it like that:
Process p = new Process();
//Fill the StartInfo of the Process----"cmd.exe"
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;//important
p.StartInfo.RedirectStandardOutput = true;//important
p.StartInfo.RedirectStandardError = false;//true,the same...
p.StartInfo.CreateNoWindow = true;//important
string strResult;
p.Start();//start the process
//for example
p.StandardInput.WriteLine("ping www.google.com ");
p.StandardInput.WriteLine("exit");//important
strResult= p.StandardOutput.ReadToEnd();
// below...you want
if (strResult.IndexOf("( 0% loss )") != -1)
{
}
else
if (strResult.IndexOf("Destination host unreachable.") != -1)
{
}
else
if (strResult.IndexOf("Request timed out.") != -1)
{
}
else
if (strResult.IndexOf("Unknown host") != -1)
{
}
else
{
}
// if end
p.Close();//close the process
|
|
|
|
|
Hi,
Thanks for the answer, it's very good.
But I have a problem, the command that I am running is "tftp.exe..."
when the transfer is successful I got the whole answer using the ReadToEnd function but when there is no tftp or the file doesn't exist I get only my command that I have sent I would expect to see "Timeout" or "File not found" as I see when I run the same command on the cmd prompt. Any Idea?
Thanks.
|
|
|
|
|
I am using visual studio .net 2008 and developing a windows forms application.
I want to use databinding and keep the business/validation logic in a separate layer (other than presentation layer).
The validation may be performed in ColumnChanged event or RowChanged event(depending upon user preference) of the datatable of the dataset.
validation error message must be shown in a Message Box
if validation is performed in ColumnChanged event and there are validation errors then the focus should be set to the control that has the validation errors.
if validation is performed in RowChanged event (i.e. user hitting the save button) and there are validation errors, then the focus should be set to the control which comes first in the tab order and has validation errors.
Is there any way i can do it?
|
|
|
|
|
I m using Crystal REports in my project
i have made setup project. but after deploying project, when i m trying to see it's giving me runtime error as below :
I have added crystal report as prerequisites ans also added reports to the appliction folder..
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.Exception: Load report failed. ---> System.Runtime.InteropServices.COMException (0x80004005): The system cannot find the path specified. at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options)
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options)
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
--- End of inner exception stack trace ---
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename)
at DPRMS.ReportViewer.btnshow_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
DPRMS
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Program%20Files/MONARCH/dprmsSetupWizard/DPRMS.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
CrystalDecisions.Windows.Forms
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.Windows.Forms/10.2.3600.0__692fbea5521e1304/CrystalDecisions.Windows.Forms.dll
----------------------------------------
CrystalDecisions.Shared
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.Shared/10.2.3600.0__692fbea5521e1304/CrystalDecisions.Shared.dll
----------------------------------------
CrystalDecisions.ReportSource
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.ReportSource/10.2.3600.0__692fbea5521e1304/CrystalDecisions.ReportSource.dll
----------------------------------------
System.Web
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll
----------------------------------------
CrystalDecisions.CrystalReports.Engine
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.CrystalReports.Engine/10.2.3600.0__692fbea5521e1304/CrystalDecisions.CrystalReports.Engine.dll
----------------------------------------
CrystalDecisions.ReportAppServer.CommLayer
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.CommLayer/10.2.3600.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.CommLayer.dll
----------------------------------------
CrystalDecisions.ReportAppServer.ClientDoc
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.ClientDoc/10.2.3600.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.ClientDoc.dll
----------------------------------------
CrystalDecisions.ReportAppServer.DataSetConversion
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.DataSetConversion/10.2.3600.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.DataSetConversion.dll
----------------------------------------
CrystalDecisions.ReportAppServer.DataDefModel
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.DataDefModel/10.2.3600.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.DataDefModel.dll
----------------------------------------
CrystalDecisions.ReportAppServer.Controllers
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.Controllers/10.2.3600.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.Controllers.dll
----------------------------------------
CrystalDecisions.ReportAppServer.CubeDefModel
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.CubeDefModel/10.2.3600.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.CubeDefModel.dll
----------------------------------------
CrystalDecisions.ReportAppServer.ReportDefModel
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.ReportDefModel/10.2.3600.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.ReportDefModel.dll
----------------------------------------
CrystalDecisions.KeyCode
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.KeyCode/10.2.3600.0__692fbea5521e1304/CrystalDecisions.KeyCode.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Is there any solution to this problem ??
Brijal Patel.
|
|
|
|
|
It seems that your report file cannot be found. Could you please post the code piece where you call ReportDocument.Load()?
Are you using Embedded or Non-Embedded report model?
Regards,
|
|
|
|
|
Hi All...can any1 assist,
im trying to pass values from a datagrid in a popup window to my main page...how can i do this?
living life on the flip side
|
|
|
|
|
If you are truly in a "Popup" (i.e. a modal dialog box), simply overload the ShowDialog method in your "popup" form to call the base implementation of ShowDialog and return the value that you want to have passed back.
private List<t> list;
.
.
.
protected void btnSubmit_Click(object sender, EventArgs e)
{
list = DataGrid.DataSource;
this.close();
}
public List<t> ShowDialog()
{
base.ShowDialog();
return list;
}
</t></t>
Have the "OK" button (or whatever flow control you have in place) set the variable you wish to return and close the form.
"I need build Skynet. Plz send code"
|
|
|
|
|
Hi Alaric...im actually using window.open and inside the window is my page...i want the datagrid values to be sent from this page to my main form
living life on the flip side
|
|
|
|
|
Use delegates. There's plenty of examples here and on the internet.
Here's a very simple example to get you started.
Create a Windows Forms Application and call it DelegateExample.
You'll already have Form1. Add another form and call it Form2 then add a TextBox to it called textBox1.
Change all the code in Form1.cs to this:
using System;
using System.Windows.Forms;
namespace DelegateExample
{
public delegate void UpdateText(string text);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.SendText = new UpdateText(Update);
frm2.Show();
}
private void Update(string text)
{
Text = text;
}
}
}
Change all the code in Form2.cs to this:
using System;
using System.Windows.Forms;
namespace DelegateExample
{
public partial class Form2 : Form
{
public UpdateText SendText;
public Form2()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
SendText(textBox1.Text);
}
}
}
When you run this - type in the TextBox on Form2 and the Text in the title bar of Form1 will change as you type.
Study the code so you understand what it's doing then you can use this principal in your situation with very little modification.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi Davey...thnx for the reply,,,ill try and see what happens...thnx again
living life on the flip side
|
|
|
|
|
Hi,
it's my first question in this site and I don't know if this one is the right forum.
I've downloaded a C# project from Desktop Development -> Progress Bar called ProgressCircle written by Utezduyar.
I extracted the zip file and I loaded in Visual Studio.
I run...
In instruction Initialize Components (the first instruction of the code) program stops and errors says "Impossible to load file or assembly 'ProgressCircle, Version=...., PublicKeyToken=....'. Impossible to warrant the authorization. (Exception HRESULT: 0x80131417).
In ProgressCircle project there is a key.snk file maybe the project is protected.
I have no idea.
Thanks in advance,
Mauro
|
|
|
|
|
Hi Mauro,
If it's a network share the .NET Framework has all sorts of concerns regarding security. Your best bet is to build then app locally, rather than from a share.
For more information on this, please refer to the below mentioned link:
http://blogs.msdn.com/shawnfa/archive/2004/12/06/276066.aspx
http://forums.msdn.microsoft.com/en-US/netfxbcl/thread/8af927ca-2713-4213-94de-f8b3f2c4364e/
You may also check the Trust Level for the framework. I would suggest you to sign/strong name your assembly to run trusted over the network.
Hope this helps.
John Adams
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
Hi,
I found many ways to get the host from url but i need the domain only.
for example - if the url is http://www.abc.com
uri.host = www.abc.com but the domain is abc.com (www is one example)
so, how do i get the domain and not the host?
Thanks,
dana Tov
|
|
|
|