Need to re-create code in new control (please help)

  • Thread starter Thread starter Ronald S. Cook
  • Start date Start date
R

Ronald S. Cook

Thanks for reading this...

Our current Win app employs a ListView control wherein the tag for an item
is, for example, "ContentManager.DataModel.PowerPointContent". The
following code exists (and works just fine) for when the user clicks on any
item within the ListView:

private void listView1_MouseClick( object sender, MouseEventArgs e )
{
Type listItemType = (Type)( ( sender as ListView ).FocusedItem.Tag );
Content newContent = (Content)Activator.CreateInstance( listItemType );
AddContent( newContent );
}

However, I'm now tasked with replacing the ListView control with ListBar
control from Infragistics. While I can easily determine which item is
clicked from e.Item.Tag, I'm not understanding how to write code in this
event:

private void ultraListBar1_ItemSelected(object sender,
Infragistics.Win.UltraWinListBar.ItemEventArgs e)
{
???
}

If anyone can help me out, I will gladly buy them a beer.

Thanks very much,
Ron
 
What are you trying to achieve via that event?
Infragistics has its own NG, full of answers. Did you get the chance to try
that?
 
Something like this maybe...

private void ultraListBar1_ItemSelected (object sender, Infragistics.Win.UltraWinListBar.ItemEventArgs
e)
{
Content newContent = e.Item.Tag as Content;
if (newContent != null)
AddContent(newContent);
}
 
Ronald said:
Thanks for reading this...

Our current Win app employs a ListView control wherein the tag for an item
is, for example, "ContentManager.DataModel.PowerPointContent". The
following code exists (and works just fine) for when the user clicks on any
item within the ListView:

private void listView1_MouseClick( object sender, MouseEventArgs e )
{
Type listItemType = (Type)( ( sender as ListView ).FocusedItem.Tag );
Content newContent = (Content)Activator.CreateInstance( listItemType );
AddContent( newContent );
}

However, I'm now tasked with replacing the ListView control with ListBar
control from Infragistics. While I can easily determine which item is
clicked from e.Item.Tag, I'm not understanding how to write code in this
event:

private void ultraListBar1_ItemSelected(object sender,
Infragistics.Win.UltraWinListBar.ItemEventArgs e)
{
???
}

If anyone can help me out, I will gladly buy them a beer.

Eh, keep the beer. I'd probably end up with Schlitz or something :)

Seriously, I have no idea what the Infragistics ListBar is. However,
assuming that
the Tag item is the same...

Type listItemType = (Type)( ( e.Item.Tag );
Content newContent = (Content)Activator.CreateInstance( listItemType );
AddContent( newContent );

Is that what you are looking for?

Matt
 
Ron,
I've never used their control, but looking at the signature, shouldn't it be
something like:

private void ultraListBar1_ItemSelected(object sender,
Infragistics.Win.UltraWinListBar.ItemEventArgs e)
{
Type UltraListBar.Item = (Type)( ( sender as UltraListBar ).SelectedItem.Tag
);
Content newContent = (Content)Activator.CreateInstance( UlttraListBar.Item );
AddContent( newContent );
}

-- where UltraListBar.Item is whatever their defined ListBar item is.

Peter
 
Thanks so much, Peter. I tried the following code (which did build
successfully):

Type UltraWinListBar = (Type)((sender as
Infragistics.Win.UltraWinListBar.Item).Tag);
Content newContent = (Content)Activator.CreateInstance(UltraWinListBar);
AddContent(newContent);

But got the following error at runtime:

"Object reference not set to an instance of an object."

Any thoughts? I greatly appreciate the help!

Ron
 
Thanks for this code snippet, Matt, but it gives me the following error at
runtime:

Unable to cast object of type 'System.String' to type 'System.Type'.

Any thoughts? I sincerely appreciate the help.

Ron
 
Ronald said:
Thanks for this code snippet, Matt, but it gives me the following error at
runtime:

Unable to cast object of type 'System.String' to type 'System.Type'.

Any thoughts? I sincerely appreciate the help.

Hm. Its telling you that the object stored in the Tag member is a
String,
rather than a type. This isn't really a problem, you can create an
object
from a NAME of a type.

Take a look at System.Activator.CreateInstance.

Matt
 
Back
Top