I know i read a post about using a BindingList for Custom Class for UltraTree and so far it works.
Here's my code
public class ScreenViewList : BindingList<ScreenClass> { } public class ScreenClass { private BindingList<ScreenObjectClass> _screenobjects = new BindingList<ScreenObjectClass>(); public int ScreenID { get; set; } public string ScreenName { get; set; } public Image PrivilegeLevel { get; set; } public BindingList<ScreenObjectClass> _Screenobjects { get { return _screenobjects; } set { _screenobjects = value; } } } public class ScreenObjectClass { private string _name; private int _scrID; private int _objID; public ScreenObjectClass(int ScrID, int ScrObjID, string Name) { _name = Name; _objID = ScrObjID; _scrID = ScrID; } public int ScreenObjectID { get { return _objID; } set { _objID = value; } } public int ScreenID { get { return _scrID; } set { _scrID = value; } } public string ObjectName { get { return _name; } set { _name = value; } } }
the property with Bold in ScreenClass, I want to Display as Image on TreeView but unable to display Image.
On the Form I do this by getting the data from the database.
ScreenViewList _screenviews = new ScreenViewList(); foreach (DataRow rowscreen in ds.Tables[0].Rows) { ScreenClass _screen = new ScreenClass(); _screen.ScreenName = rowscreen["ScreenName"].ToString(); _screen.ScreenID = Convert.ToInt32(rowscreen["ScreenID"]) ; _screen.PrivilegeLevel = Imagelist1.Images[0]; _screenviews.Add(_screen); this.LoadScreenObjects(Convert.ToInt32(rowscreen["ScreenID"]),_screen); } tv.BeginUpdate(); BindingSource bg = new BindingSource(); bg.DataSource = _screenviews; tv.DataSource = bg; tv.EndUpdate(); I see the PrivilegeLevel Column with values as System.Drawing. Can someone please correct me what i am doing wrong here.
Thanks
Regarding my last reply, I figured out that column sets were being recorded at design-time because I had set the tree's DataSource. By moving initialization of DataSource to the form load handler, and deleting all the items in the ColumnSettings.ColumnSets collection one last time, I got the tree to always fire the ColumnSetGenerated event.
Your instincts were correct. The ColumnsSetGenerated event wasn't being fired. I deleted the columnsets that had been added by the UltraDataSource designer, then I got the event. By adding the new unbound column, hiding the source column, and mapping the source to an image in InitializeDataNode, I got the desired cell appearance. The only non-intuitive thing about the above advice is that the header caption cannot be the empty string or null, both of which are apparently silently rejected. When I set the column Text to a single space, I got a header with just the image.
Thanks. I appreciate that you and Brian have both been quick to respond to my questions.
The next step is to allow selection of the image via a dropdown listbox, and to propagate that back to the hidden column.
bobgru said:1) Handle ColumnSetGenerated and set the EditorControl to an instance of UltraPictureBox. This didn't change the cell appearance (still get image on left, integer on right).
I don't see how this could possibly be. Something must be wrong in the code and the Editor must be getting overridden by some other settings. An UltraPictureBox cannot display text.
In any case, this won't work for what you want. The UltraPictureBox will attempt to convert the value of the cell into an image and in this case, that's not possible, because the Value of the field is not an image, it's a number.
bobgru said:2) Handle ColumnSetGenerated and set ColumnSet.Columns["MyCol"].HeaderAppearance.Image to an image object. I expected this to show the image in the header instead of the column name, but there was no change. I also tried changing the HeaderAppearance.BackColor to no effect, so I suspect I may be missing something.
Once again, I don't see how the behavior you are describing is possible. Something in your code must be overriding the settings you are using afte you set them. Either that or the code changes you are making are not getting built and you are basically running an old exe.
Here's what I would do:
1) I would add a new unbound column to the ColumnSet and set it's DataType to Bitmap. Then I would hide the existing column of integers. Then use the InitializeDataNode event to populate the Value of the Bitmap cell with the image you want based on the integer value in the hidden column.
2) I think you are on the right track here, but you will probably also need to set the Caption on the Column header to get rid of the text - assuming you want just the image and not the text.
I want to do a similar thing: I have a tree in grid mode with an integer column, but I want to display an image based on the integer, rather than the integer itself.
I quickly got an image into rendered cells by handling InitializeDataNode and setting Cells["MyCol"].Appearance.Image. For now I'm limiting the column to two values so I just set Image to an image object rather than an imagelist index. The image appeared at the left side of the cell, with the integer itself at the right. I would like to omit the integer and show just the image.
I would also like to display an image in the header instead of a string.
From the forums and online help I have gotten varous suggestions, but don't have the desired behavior yet.
1) Handle ColumnSetGenerated and set the EditorControl to an instance of UltraPictureBox. This didn't change the cell appearance (still get image on left, integer on right).
2) Handle ColumnSetGenerated and set ColumnSet.Columns["MyCol"].HeaderAppearance.Image to an image object. I expected this to show the image in the header instead of the column name, but there was no change. I also tried changing the HeaderAppearance.BackColor to no effect, so I suspect I may be missing something.
I attached a small project showing what I did.
aperregatturv said:1. Instead of using an Image i thought of using a Integer value (thats what stored in the database. So, my question is it displays one the 3 values (0,1 or 2) so instead of showing numbers i would like to show a dropdown for that column where use can pick one from the list.
1. Instead of using an Image i thought of using a Integer value (thats what stored in the database. So, my question is
it displays one the 3 values (0,1 or 2) so instead of showing numbers i would like to show a dropdown for that column where use can pick one from the list.
In that case, you can use the ValueList property of the column.
aperregatturv said:2. The Cell Header width looks like its fixed how i do i change it. I tried everthing from AutoSizeColumns and nothing seems to work. It looks like this. | Screen | Level | ||--> the end of the treeview width | ID | Name| Instead i would like it this way| Screen | Level ||--> the end of the treeview width -- | ID | Name ||
2. The Cell Header width looks like its fixed how i do i change it. I tried everthing from AutoSizeColumns and nothing seems to work.
It looks like this.
| Screen | Level | ||--> the end of the treeview width
| ID | Name|
Instead i would like it this way
| Screen | Level ||--> the end of the treeview width
-- | ID | Name ||
I'm not sure what you mean by "fixed". A user can click and drag the edge of a column to size it If you want the columns to fill the width of the tree, then you would use the AutoFitColumns property. If you want to set the width of a particular column, then I think you use column.LayoutInfo.PreferresCellSize.
aperregatturv said:3. When using Outlook Express Style I am unable to show certain columns (The column Header width automatically resizes to the size of the Treeview here strange)Top LevelI would like it to see this. | Screen || |ID | Name I cannot get the Name Field to display if the Top level does not have the second column shown. How do I get the data to display one column for Top level and 2 or 3 columns for the Child node.
3. When using Outlook Express Style I am unable to show certain columns (The column Header width automatically resizes to the size of the Treeview here strange)
Top Level
I would like it to see this.
| Screen ||
|ID | Name
I cannot get the Name Field to display if the Top level does not have the second column shown. How do I get the data to display one column for Top level and 2 or 3 columns for the Child node.
In OutlookExpress style, every level in the hierarchy has to display the same number of columns. The ColumnSet is generated based on the root-level of the data. So if your too level only has one column, then you can only display one column in every level. You can probably add a column to the root level columnset and get this to work.