|
Is there a simple way to get the number of files in a current directory?
|
|
|
|
|
|
Directory.GetFiles(".").Length
|
|
|
|
|
Thank you Gentlemen. I knew it was simple but couldn't find it readily.
|
|
|
|
|
hi,
i have a list view control with columns :
Book Name, Author, date released, cpies sold
the book name represents the name of the object
i'd like to do sorting by each header ny cliking the header
the problem is that i only have Auto sort to the object name
i.e the book name header, but i like also to do to all the aother header
haw can i do it?
or should i use the datagridview insted??
THNKS
Have Fun
Never forget it
|
|
|
|
|
Hi!
You should use the ListViewItemSorter property of the ListView . The documentation on MSDN contains examples for this.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi all,
I have devoloped an appliction which will set my internet settings.
I have listbox,textbox etc.
The basic idea is that in a button click event the settings that i see in my text boxes should get applied to my computer.
it takes the values from a xml file.
now i am at a point where it displays all the values.
Now i want it get applied on my computer so that on a button clck i can switch between two of my service providers.
So i need help in knowing "how can i make the settings that is in my text box to get applied to my computer so that on a button click i can switch the internet connections".
May be if i show you my code it will be better
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Net;
using System.Diagnostics;
using System.Threading;
namespace InternetApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
XmlTextReader xmltxtRdr = new XmlTextReader("XMLFile1.xml");
private void btnSwitch_Click(object sender, EventArgs e)
{
Process netshobj = new Process();
netshobj.StartInfo.FileName = "netsh";
netshobj.StartInfo.CreateNoWindow = true;
netshobj.ErrorDataReceived += new DataReceivedEventHandler(netshobj_ErrorDataReceived);
//netshobj.StartInfo.Arguments = "netsh";
// Here i tried these to check whether it will work or not and the result is that it shows a netsh window and tahts it.My settings are nit changing//
netshobj.StartInfo.Arguments = "interface ip set dns 'Local Area Connection' static 192.168.1.255 primary";
try
{
netshobj.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void netshobj_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
MessageBox.Show("The method or operation is not implemented.");
}
private void lstProvider_SelectedIndexChanged(object sender, EventArgs e)
{
GetConnctionSettings( lstProvider.Text);
}
private void GetConnctionSettings(string provider)
{
XmlTextReader xmlTxtRdr = new XmlTextReader("XMLFile1.xml");
while (xmlTxtRdr.Read())
{
if (xmlTxtRdr.Name.ToString() == "connectionName")
{
if (xmlTxtRdr.ReadString().Equals(provider))
{
xmlTxtRdr.ReadToNextSibling("SubNetMask");
txtSubnet1.Text = xmlTxtRdr.ReadString();
xmlTxtRdr.ReadToNextSibling("DefaultGateway");
txtDefaultgateway.Text = xmlTxtRdr.ReadString();
xmlTxtRdr.ReadToNextSibling("DNS1");
txtPrimarydns.Text = xmlTxtRdr.ReadString();
xmlTxtRdr.ReadToNextSibling("DNS2");
txtSecondarydns1.Text = xmlTxtRdr.ReadString();
xmlTxtRdr.ReadToNextSibling("DNS3");
txtSecondarydns2.Text = xmlTxtRdr.ReadString();
GetIP();
}
}
}
}
public void GetIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
//MessageBox.Show(strHostName);
IPAddress[] addr = ipEntry.AddressList;
//MessageBox.Show(addr[0].ToString());
txtSubnet2.Text = (addr[0].ToString());
//return addr[addr.Length-1].ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
//Load connection names to list box.
getConnectionNamestoListBox();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void getConnectionNamestoListBox()
{
while (xmltxtRdr.Read())
{
if (xmltxtRdr.Name.ToString() == "connectionName")
{
lstProvider.Items.Add(xmltxtRdr.ReadString());
}
}
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void btnCancel_Click(object sender, EventArgs e)
{
MessageBox.Show("You are about to quit Internet Switcher ");
this.Close();
}
}
}
Thanking You
j
|
|
|
|
|
Hello,
I have two webparts. They are connected - one is the provider, one the consumer. The consumer maintains a gridview. Whenever I data arrives from the provider, I call the CreateChildControls in my ConnectionConsumer method. Thus my gridview is rebuilt. But - the CreateChildControls has already been called once, at this point. I'm thinking I should go about this in a different manner. Any ideas? Thank you very much in advance.
Morten
|
|
|
|
|
Hi All,
I have created a delegate and called method in one process. And I am trying to fire event corresponding to this delegate. Programm was running without errors and exceptions. But event handing method was not firing.
could you please suggest me what I made wrong.
Thanks for great support and knowledge sharing.
--------------------------------------------------------------------------------
I have created a form with one delegate:
namespace DelegateDefenitionContainedApplication
{
public delegate void HiSrinivas(object sender, EventArgs e);
public partial class Form1 : Form
{
public static void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("You are succeeded");
}
}
}
And I have created one console application using following way:
namespace EventCaller
{
class myEventClass
{
public static event DelegateDefenitionContainedApplication.HiSrinivas ClickMe;
public void abc()
{
ClickMe += new DelegateDefenitionContainedApplication.HiSrinivas(DelegateDefenitionContainedApplication.Form1.button1_Click);
}
}
class Program
{
static void Main(string[] args)
{
try
{
myEventClass mySrinivas = new myEventClass();
mySrinivas.abc();
}
}
}
}
|
|
|
|
|
nallanch_srinivas wrote: I have created a delegate and called method in one process. And I am trying to fire event corresponding to this delegate. Programm was running without errors and exceptions. But event handing method was not firing.
From the source code you have shown, it looks like ClickMe is never called. If you add a call to ClickMe after your call to abc(), the event should fire.
Also, your code looks strange in other ways. If you want a console app that fires an event, then there is no need for Form1 to be a form at all. It could easily derive directly from Object and still work.
If you want to display a form that executes code when the button is pressed, you might want to make a Forms application, and let the IDE do a lot of the work for you.
Nathan
|
|
|
|
|
Hi all,
when building a C# project with a same output directory, the generated dlls are erased even if they don't have the same name.
For instance,
1- I build my project in Debug
2- it generates projectd.dll into C:\
3- I build my project in Release
4- it generates project.dll into C:\
5- the projectd.dll was removed from C:\
is there a way to avoid that ?
thanks for help
kort
|
|
|
|
|
Mmm, keep the debug in debug folder and vice-versa, and run a post-build batch file to copy the file to C:\ ?
|
|
|
|
|
how can i add a hyper link to a desktop application ?
I have a small notifier pops up, i want to add a link to the text written on the popup.
How can i do it c#, .net 2005, deskop app.
Thanks
|
|
|
|
|
Personally I use a link label and use System.Diagnostics.Process.Start(...) in its Click event
|
|
|
|
|
Agreed, link label is designed to look like a link, and changes the cursor to 'the hand'. So it should be fairly obvious to people that it is a link.
Then use Process.Start like Davey says.
Also note, that is you use Process.Start(WebAddress); and you have a browser window open already, it will navigate away from the page the user is viewing and towards the page you supplied, its like a browser hijack!
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
I have a WinForms application whose main form contains a custom user control (and that custom user control, in turn, contains other custom user controls, etc).
If I want the main form to handle keystrokes (such as Ctrl-S or Ctrl-X) without allowing the inner user controls to handle them first, is there any easy way I can guarantee that the main form will pick up the keystroke first (100% of the time)?
|
|
|
|
|
Hi,
you will need the Form.KeyPreview property, the Form.KeyDown event, and the
KeyEventArgs.Handled and KeyEventArgs.SuppressKeyPress properties.
|
|
|
|
|
Thanks a lot. The topic of the intricacies of handling keystrokes is probably worth an article in itself.
In my test application, I made a form with a listbox in it. The listbox contained several items, including an item that started with "S", and the application handled the Control-S functionality by displaying a messagebox.
Although the Control-S messagebox still showed up when Control-S was pressed while the listbox had focus, the application also highlighted the listbox item that started with "S" (default functionality for a listbox is to highlight based on keypresses regardless of which modifiers are also pressed). The only way to suppress this functionality was to set the KeyEventArgs.SuppressKeyPress property of the Listbox.KeyDown event (it couldn't be done in the Form.KeyDown event).
Thus, I can guarantee that my main form handles keypresses like I want it to, but I still have to hunt down the sub-controls one-by-one to make sure they don't handle keypresses when I don't want them to.
|
|
|
|
|
Is there a way I can limit the number of characters inside the PropertyGrid items. I want to allow only 5 characters. Please help
|
|
|
|
|
The only thing you can do is to validate the data *after* the user has already entered it. There is a third-party control, which does allow you to restrict what the user can enter. Check it out here[^].
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Is there a possiblity to attach a textbox within the PropertyGrid control griditem
so this way i can set the textbox.MaximumLength =5 or something.
|
|
|
|
|
Unfortuantely, no. The data entry portion of the PropertyGrid is not accessible and there are no hooks for "when data is being entered". So you cannot restrict what is entered while it's being entered or swap out the entry control for you own control (even if it's just a TextBox).
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
|
Maybe I should have been more clear in my answer. There is no correct way to do this. The article you posted uses internal control names to find the proper control inside the PropertyGrid. The name "System.Windows.Forms.PropertyGridInternal.PropertyGridView+GridViewEdit" is internal to the PropertyGrid and could be changed by Microsoft. So this means your application may just stop working at some point.
Using Reflection (or in this case internal control names), you can gain access to any field/property/method/event in a .Net class. This includes all private and internal members. It is highly recommended that you don't do this, because again the creator of the class can change the inner workings at anytime (thus breaking your application).
That aside, the article's code is pretty straight forward. An attribute is created so that the developer can mark each appropriate property with a "format". Then the custom PropertyGrid looks for that format and restricts the input.
I *think* that you would need to:
1. Create an attribute that takes a maximum length and apply this attribute to your properties.
2. In CustomPropertyGrid, you can remove the m_TextBox_TextChanged method, because you won't need to use that to enforce the max length.
3. In CustomPropertyGrid, replace the parts of code where the m_TextBox_TextChanged method is assigned to and removed from the TextChanged event so that you set and reset the MaxLength property, respectivly.
Give it a shot, if you have problems then email me and I can help you work through it.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thanks Tom, I appreicated the time you took out to answer me. Can you enlightened more as you said that "the creator of the class can change the inner workings at anytime (thus breaking your application).". What about if lets say i run my application on .Net version 2.0 and even microsoft change the PropertyGrid control properties in .Net vesrsion 3.0 or so, will that effect ? Excuse me, as you have propbably have figured it out that I am a newbie and willing to explorer and learn more with people like you. Atleast, you have given me some thought to look after Reflection and what is that all about.
Thanks
|
|
|
|