|
Andrei,
I am sorry to be so bold as to state that I am not sure how I would implement the collection to iterate through. I am quite new to C# and coming from VB, collections are a different breed (for me at least.) I haven't gotten that far yet. Could you find yourself to provide a very small example of how to implement this particular collection. I did look to see if the SelectedRows Property included the Collection but couldn't find it. I did see something about GetEnumerator but I'm lost.
Thanks though.
F
|
|
|
|
|
I will give you an example, supposing you have a DataGridView called dgv
DataGridViewSelectedRowCollection collection = dgv.SelectedRows;
foreach (DataGridViewRow row in collection)
{
}
row is a DataGridViewRow with which you have work before...right? Of course you will have to place this code somewhere in an event, or function...you'll figure that part out.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Andrei,
That was the ticket. After your response I researched it and now I have a good understanding of how this works. Again, thank you both for your responses.
Best regard,
F
|
|
|
|
|
Hi,
Consider the next situation
I Have this Attribute
<br />
[AttributeUsage(BlaBlaBla)]<br />
public class myattribute:Attribute<br />
{<br />
...<br />
...<br />
...<br />
}<br />
Now - Inside My Form
<br />
public class MyForm:Form<br />
{<br />
[myattribute]<br />
Button button1;<br />
<br />
Public MyForm()<br />
{<br />
button1 = new Button();<br />
}<br />
}<br />
now - using reflection - how can i get this attribute from button1?
the next gode does not work
<br />
Type Y = button1.GetType();<br />
object[] obj = T.GetCustomAttributes(typeof(myattribute),false);<br />
obj.Length is 0
(I Guess it because T.GetCustomAttributes returns the attributes of Type Button and not of its instance button1)
so... how can i get this attribute from button1?
Thanks
|
|
|
|
|
It's not working because your code is asking for all custom attributes on the Button class, not on your button1 field.
Here's how you should get custom attributes from a field:
Type myFormType = typeof(MyForm);
FieldInfo button1Field = myFormType.GetField("button1", BindingFlags.NonPublic | BindingFlags.Instance);
object[] customAttributes = button1Field.GetCustomAttributes(typeof(myattribute), false);
|
|
|
|
|
|
Rather than looking at the class, you have to look at the fields that belong to the class. Try this instead:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace Test
{
[AttributeUsage(AttributeTargets.All)]
public class myattribute : Attribute
{
public myattribute() : base() { }
}
public partial class Form1 : Form
{
[myattribute]
Button b1;
public Form1()
{
b1 = new Button();
this.Controls.Add(b1);
FieldInfo[] fis = this.GetType().GetFields(
BindingFlags.Instance | BindingFlags.NonPublic |
BindingFlags.Public);
foreach (FieldInfo fi in fis)
{
object[] o = fi.GetCustomAttributes(typeof(myattribute), true);
if (o.Length != 0)
{
Console.WriteLine("Hello from o");
}
}
}
}
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
Can anyone help?
I want to be able to drag and drop text into a Rich Text Edit or Memo type component but I want to drop the text at the position of the mouse cursor when the mouse button is released?
I have read a few articles so I can do drag and drop but how to drop at the mouse cursor position?
Thanks In Advance
|
|
|
|
|
I would suggest utilising the MouseUp event handler, and use HitTestInfo to find the coordinates of the pointer...
HitTest(e.X,e.Y)
Then set the cursor to this position, then perform your drop method at that position
Hope this helps
Give me strength, give me caffeine
|
|
|
|
|
Hey people
Was just wondering whether anyone knew whether this if statement is gonna be system dependent or not
e.KeyChar == 13, where e is a KeyPressEventArgs
Am trying to allow a text box to perform an action when return is pressed
The method works on my comptuer, but will it on another keyboard?
Cheers
Give me strength, give me caffeine
|
|
|
|
|
It's not system dependent because if you look at ASCII Table you can see that it's a standard notation for CR.
c#_keithy wrote: e.KeyChar == 13
My recommendation is to use the Keys enumeration to compare with e.KeyChar
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Just found an mdn article on using Keypress events, which uses the following compare statement
e.KeyChar == (char)Keys.Return
KeyPressArticle[^]
Thanks for your input
Give me strength, give me caffeine
|
|
|
|
|
Hi,
I am able to list all available providers in the system presently windows using c#.
I can do that with the wql query i.e. select * from __Provider. But if i want to determine what type of provider it is, like say an instance provider or method provider etc then how do I determine that?
Also different classes use different types of providers like classes with events use event providers and those with use of methods use method provider.
But how to determine which event or method provider etc is being used by the class?
|
|
|
|
|
First og all.....I'm a newbee.....!!!
I need to make a service, that on a given time executes an application (APPL_1).
Furthermore I need to be able to tell the service to execute APPL_1 manually from another og my C# applications (APPL_2) by clicking a button.
So what I need is a way to "communicate" between the service and APPL_2 in order to execute APPL_1.
I hope the above isn't to cryptic.. *ss*
All kind of "help" would be appriciated.
/Lars Lie
|
|
|
|
|
If you need to communicate between processes, you have several options.
Look up a technology called .NET remoting. It allows you to "communicate" with other processes. There are several articles and examples on this site.
There are plenty of other options too: web services (your service exists on the web, called by either other web applications or desktop applications), as well as the new Windows Communication Foundation technology (WCF). Any of those 3 should work for you.
|
|
|
|
|
Since there's no default method that let's me unhook all listeners from an event at once, I sometimes do this:
public event PropertyChangedEventHandler PropertyChanged;
public void UnHook()
{
if (this.PropertyChanged != null)
{
Delegate[] list = this.PropertyChanged.GetInvocationList();
foreach (Delegate d in list) this.PropertyChanged -= d as PropertyChangedEventHandler;
}
}
However, since I find it kind of annoying to write this code for different types of events I'd really like to be able to do something this:
public static void Unhook<T>(event x)
{
Delegate[] list = x.GetInvocationList();
foreach (Delegate d in list) x -= d as T;
}
My question: Does anyone know of a way to implement parsing of events as method arguments? Thanks in advance...
Standards are great! Everybody should have one!
|
|
|
|
|
Let me point you over towards EventPools[^]. They tackle the management of events in a different way.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Ok, that looks promising, thanks. Still I'm curious if it's in anyway possible to realize parsing of events as arguments...
Standards are great! Everybody should have one!
|
|
|
|
|
Great article. I'm going to explorer this idea some more for some UI stuff I'm currently working on.
|
|
|
|
|
Thanks for that. Ever since I first stumbled on Marc's article I've found it easier to use EventPools. This article just grew out of my heavy use of EventPool - BTW, it makes implementing the MVC pattern really straight forward.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hello Developers. I realize this is a C# message board but I can't help but ask folks for advice. I recently upgraded our teams Sharepoint site from 2.0 to 3.0. I've run into a problem adding a content database but I'm afraid my biggest problem is I can't change the configuration database. As of right now, the site and the databases are on separate servers but we need them on the same server. If anyone can help me with this problem or send me a link that could help, I'd greatly appreciate it. Thanks for all responses in advance.
Lester
http://www.lestersconyers.com
|
|
|
|
|
hi friends
i want to read a txt file using c#. i have some txt files with different informations. ex
txt 1
customr:abc
article:zxy
page number: 4
txt 2
customr:fgh
article:ser
page number: 3
txt 3
customr:yhu
article:fgr
page number:10
the problem is : how i can find the value. how to read this txt file. i tried. but it is reading only if we fave given the full length. i want to find what will be the value of customer of txt 1.
plz do help me.
thank u.
|
|
|
|
|
string text = File.ReadAllText(filename)
You can then search for different strings within your string using IndexOf, Substring etc. If you don't like this approach study MDSN for System.IO.File class. It has a lot of static methods that can help you read a text file in different ways.
Do your best to be the best
|
|
|
|
|
You can use the readline function of the StreamReader. If the line contains the desired text such as txt 1, then read the next line and you will get the customer name etc.
|
|
|
|