|
Hi,
try this in the click handler of a button on your form, that has an
empty but visible ListView named lv:
lv.SuspendLayout();
for (int i=0; i<100000; i++) {
lv.Items.Add("item "+i);
}
lv.ResumeLayout();
and try the same without Suspend/ResumeLayout; you wont need a stopwatch
to experience the difference.
|
|
|
|
|
Always great examples Luc!
I really hope you make the MVP next time!
Got my '5'!
All the best,
Martin
|
|
|
|
|
Hello,
i would like to have a windows form combo box populated from an xml file,
here is the format of the xml file
<br />
"<"ITEMS">"<br />
"<"NAME">""<"/"NAME">"<br />
"<"URL">""<"/"URL>"<br />
"<"/"ITEMS">"<br />
i want to take these two items and assign them as variables
NewName;
NewUrl;
which i will then populate the combo box with...
and read them with this code
<br />
<br />
<br />
<br />
<br />
-- modified at 15:46 Monday 9th July, 2007
The Devil Lives in all of us, It's up to you to let HIM/HER out!!!!!
|
|
|
|
|
Not sure what you want, but does this help?
XmlDocument doc = new XmlDocument();
doc.Load("XMLFile1.xml");
XmlNodeList names = doc.GetElementsByTagName("NAME");
XmlNodeList urls = doc.GetElementsByTagName("URL");
foreach (XmlNode node in names)
{
Console.WriteLine(node.InnerText);
}
foreach (XmlNode node in urls)
{
Console.WriteLine(node.InnerText);
} Tip: Check the Ignore HTML... option if you're posting XML snippets.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
hey,
thanks for your response,
how can i load the list of names, urls to a combobox based on your code?
thanks again
The Devil Lives in all of us, It's up to you to let HIM/HER out!!!!!
|
|
|
|
|
Mate, you already know how to add items to a combobox - you're doing it in your code. Just replace my Console.WriteLine() statements with your code.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
ok,
i'm using this, but the code is only loading one node to my combobox, can someone help me with this?
<br />
XmlDocument doc = new XmlDocument();<br />
doc.Load("ComboItemName.xml");<br />
XmlNodeList Nodes = doc.GetElementsByTagName("NAME");<br />
foreach (XmlNode node in Nodes)<br />
{<br />
NewNameLoad = node.InnerText.ToString();<br />
}<br />
XmlNodeList NodesA = doc.GetElementsByTagName("URL");<br />
foreach (XmlNode node in NodesA)<br />
{<br />
NewUrlLoad = node.InnerText.ToString();<br />
}<br />
comboChannels.Items.Add(new RSSChannel(NewNameLoad, NewUrlLoad));<br />
comboChannels.SelectedIndex = 0;<br />
<br />
-- modified at 13:49 Wednesday 11th July, 2007
The Devil Lives in all of us, It's up to you to let HIM/HER out!!!!!
|
|
|
|
|
Hi to all,
I want to program a AGENDA like outlook for my appointments. I want to use drag & drop for modify appointments and make click over a cell and to create a new one. Can anybody help me or guide me?
Thanks a lot.
_______
NaOH
|
|
|
|
|
how about you start programming it and we can guide you from there?
The Devil Lives in all of us, It's up to you to let HIM/HER out!!!!!
|
|
|
|
|
Hi velkropie, i want to use de datagridview control to make a personal agenda. It is like Outlook format. To create appointments, drag and drop across the cells, and this new controls (appointments, 'citas' in spanish) can be stored in a database.
I begin with Visual Studio 2005 and the datagridview control.
I need code examples to built this grid, format it and to insert new controls (labels for example) in the grid and a database.
Thanks a lottt.
_______
NaOH
|
|
|
|
|
here is you drag and drop to get you started
void grdCampaigns_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
if (e.Button == MouseButtons.Right)<br />
{<br />
DataGridView.HitTestInfo info = grdCampaigns.HitTest(e.X, e.Y);<br />
if (info.RowIndex >= 0)<br />
{<br />
DataRowView view = (DataRowView)<br />
grdCampaigns.Rows[info.RowIndex].DataBoundItem;<br />
if (view != null)<br />
grdCampaigns.DoDragDrop(view, DragDropEffects.Copy);<br />
}<br />
}<br />
}
void lstCategories_DragEnter(object sender, DragEventArgs e)<br />
{<br />
e.Effect = DragDropEffects.Copy;<br />
}
Collapse
void lstCategories_DragDrop(object sender, DragEventArgs e)<br />
{<br />
if (e.Data.GetDataPresent(typeof(DataRowView)))<br />
{<br />
Point p = lstCategories.PointToClient(new Point(e.X,e.Y));<br />
int index = lstCategories.IndexFromPoint(p);<br />
if (index >= 0)<br />
{<br />
DataRowView category = (DataRowView)lstCategories.Items[index];<br />
DataRowView campaign = (DataRowView)<br />
e.Data.GetData(typeof(DataRowView));<br />
int newID = (int)category[0];<br />
int oldID = (int)campaign[1];<br />
if (oldID != newID)<br />
{<br />
campaign.BeginEdit();<br />
campaign[1] = newID;<br />
campaign.EndEdit();<br />
}<br />
}<br />
}<br />
}
The Devil Lives in all of us, It's up to you to let HIM/HER out!!!!!
|
|
|
|
|
I have the following line of code
ResponseProcessingCSP rpCSP = (ResponseProcessingCSP)CSPManager.Instance.GetResponseProcessesingCSP(ChannelID);<br />
GetResponseProcessesingCSP returns an object of type IResponseProcessingCSP
ResponseProcessingCSP inherits from type IResponseProcessingCSP as well.
This throws an error saying "Unable to cast object of type 'ResponseProcessingCSP' to 'ResponseProcessingCSP'
What would be causing this?
|
|
|
|
|
Could the two types have the same name, but come from different assemblies (or namespaces)?
Does fully qualifying the type with the namespace help?
e.g. MyCompany.MyComponent.ResponseProcessingCSP
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
Hello,
joelbasson wrote: "Unable to cast object of type 'ResponseProcessingCSP' to 'ResponseProcessingCSP'
Doesn't it say "Unable to cast object of type 'IResponseProcessingCSP' to 'ResponseProcessingCSP'"?
joelbasson wrote: ResponseProcessingCSP inherits from type IResponseProcessingCSP
But it was instanciated as IResponseProcessingCSP, and you can not Up'cast' it , I think!
Maybe this two examples help you:
1) Your problem (You cannot make a button out of a control)
Control _control = new Control();
Button _button = _control as Button;
if(_button!=null)
{
}
else
{
}
2)But you can make a Button, hold it as Control and when you need it cast it back to Button
Button _button = new Button();
Control _control = _button;
Button _newbutton = _control as Button;
if(_newbutton!=null)
{
}
else
{
}
Hope it helps!
P.S.: You should use the 'as' operator, which will not throw an exception, if the casting is not possible!
All the best,
Martin
|
|
|
|
|
Martin# wrote: But it was instanciated as IResponseProcessingCSP, and you can not Up'cast' it , I think!
You can't instantiate an interface.
Martin# wrote: You should use the 'as' operator, which will not throw an exception, if the casting is not possible!
Perhaps there would be a situation where you do want an exception. Perhaps a case where the situation should never exist and so will be an exceptional case. Use "as" only when the posibility is frequent and expected.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
So far I've never used as , I use is to test and then cast as appropriate.
|
|
|
|
|
Hi,
functionally as + nulltest is equivalent to is + (cast)
but performance wise as + nulltest is bound to be faster
since is+(cast) is checking the type twice.
So as has more value for me than is; I will use as all the
time, except when the casted object is not needed at all, then is will do.
|
|
|
|
|
YES,
I also whant to prevent the double typecheck!
And there are very few situations where I do not whant to cast and only make the check. (1 out of 100 in my project)
All the best,
Martin
|
|
|
|
|
Very true, and I'll have to keep that in mind, but one of my more complicated uses of is + cast is this sort of thing:
if ( o is typeA ) do something with (typeA) o
else if ( o is typeB ) do something with (typeB) o
else if ( o is typeC ) do something with (typeC) o
...
I don't think that would translate well to using as :
typeA tempA ;
typeB tempB ;
typeC tempC ;
...
if ( ( tempA = o as typeA ) != null ) do something with tempA
else if ( ( tempB = o as typeB ) != null ) do something with tempB
else if ( ( tempC = o as typeC ) != null ) do something with tempC
...
And is + cast works with all types, not just reference types.
|
|
|
|
|
Hi,
OK, I guess that's why both forms exist.
My use is mostly simple, as in find all Buttons in myForm.Controls
(So I would appreciate a forgiving variant of foreach that does this automatically
without throwing when some non-Button Controls are present)
Type checking value types is something I havent needed much, if at all.
If and when I need it, the compiler will remind me to use is (and then
I will remember this thread).
Regards.
|
|
|
|
|
Hello,
Colin Angus Mackay wrote: You can't instantiate an interface.
True, but what does that mean to his problem. Hmmm!
The method returns an IResponsableProcessingCSP instance and can not be casted too an derived class.
Would it have the same effect (exception) if it was originaly instanciated as on other derived class from IResponsableProcessingCSP?
Colin Angus Mackay wrote: Perhaps there would be a situation where you do want an exception. Perhaps a case where the situation should never exist and so will be an exceptional case. Use "as" only when the posibility is frequent and expected.
Personaly, I would also use the as operator for that and check !=null, and throw my own Exception!
But that's maybe a matter of taste.
All the best,
Martin
|
|
|
|
|
Martin# wrote: Colin Angus Mackay wrote:
You can't instantiate an interface.
True
Martin# wrote: The method returns an IResponsableProcessingCSP instance
You argree with me, then contradict yourself.
You cannot have an instance of an interface. You can only have a reference to one. The instance is of some concrete object that happens to implement the interface.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
Hello Colin,
Colin Angus Mackay wrote: You cannot have an instance of an interface. You can only have a reference to one.
Ok, ok!
It should be obvious that I'm not using the write programming vocabulary!
Colin Angus Mackay wrote: The instance is of some concrete object that happens to implement the interface.
That's what I was trying to explain! (Did it in a poor way, off course!)
So again my question:
Would it have the same effect (Exception):
The method returns a reference to the interface, which was implemented from classA but casted from classB (which also implements the interface)?
-- modified at 1:31 Tuesday 10th July, 2007
Wa sjust reading the answere from Vikram A Punathambekar [^]
Thanks for your time and patience!
All the best,
Martin
|
|
|
|
|
Hello Colin,
Maybe you find time to look threw my example[^]!
Hope you can help me!
Thanks again for your time!
All the best,
Martin
|
|
|
|
|
Martin# wrote: But it was instanciated as IResponseProcessingCSP
Apart from the fact that an interface cannot be instantiated, this code will work perfectly fine:
ITheInterface iface = new ClassThatImplementsITheInterface(); As far as the underlying object is concerned, it does NOT matter what type you use to reference it*, what matters is the ctor used to instantiate the type.
* As long as it represents a valid cast, of course.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|