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
If you want the column to display as a picture, then I think what you need to do is use an editor. Place an UltraPictureBox control on the form. Then in the ColumnSetGenerated event, set the EditorControl property of the column to the UltraPictureBox.
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.
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: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.
I'm pretty sure the caption actually default to null or empty. But in that case, the header will display the Key of the column.
If the caption defaults to null or empty and the resultant behavior is to display the key, I saw the expected behavior. My question is then, what's the proper way to hide the caption text?
Setting Text to space effectively made the caption invisible, but it smells like a workaround.
Using a single space is the easiest way.
Earlier I was using directly binding dataset to Datagrid and at in some other function used to get that dataset from grid. e.g.
dataSetSubTabData = (
DataSet) ugGridData.DataSource;
But after changing grid datasource to UltraDataSource, above line of code is not working and gives wrong casting exception.
Is there any way to get the dataset from grid now? I need that dataset because some operation needs to be done on that.
Thanks!! I got the solution.
If you bound two grids to a table and a relation the same DataSet, then the BindingManager takes care of this for you.
An UltraDataSource does not have Relationship data, so there's really no wasy way to do this.
May I asked why you switched to an UltraDataSource rather than binding the grids directly to the DataSource?
That issue is resolved. I created datatable from grid. There is one more scenario.
I have two grids and both are using two different ultradataSource. Now , what I need is based on rows selected in first grid, data should be populated in 2 nd grid.
I have already added a relation in dataset which contains datatables for these two grid. Everything was working fine till i chnaged the datasouce to UltraDataSource from direct dataset.
Now, no matter which row user selects in top grid, bottom grid displays all the rows.
Any suggestion?
Thanks!!
It looks like you are adding a table to the DataSet. An UltraDataSource doesn't have tables, so there's no way to add a table to it. It uses a Band structure. But since I don't know why you are adding a table, it's impossible for me to guess what you need to do here.
This is what I am trying to do. Do you see any alternative for this.
foreach
(System.Windows.Forms.Control ctrlSubTabInnerControl in ctrlSubTabControl.Controls)
{
if (ctrlSubTabInnerControl.GetType() == typeof (UltraGrid))
ugGridData = (
UltraGrid) ctrlSubTabInnerControl;
dsSubTabData = (
if (!mdsPreviewDataset.Tables.Contains(dsSubTabData.Tables[0].TableName))
mdsPreviewDataset.Tables.Add(dsSubTabData.Tables[0].Copy());
}