Hello all,
I am trying to bind an UnBound column of type Checkbox which is displayed as an IMAGE. However, after binding, i cannot view the image. The column appears as white empty cell. However, the column works properly as a checkbox when i click on that empty cell. Here is the code that i wrote that adds the unbound column.
//--------------------------------------------------------//ADD DELETE Column in the beginning.//--------------------------------------------------------if (!ugProcedures.DisplayLayout.Bands[0].Columns.Exists("Delete")){ ugProcedures.DisplayLayout.Bands[0].Columns.Insert(0, "Delete");
ugProcedures.DisplayLayout.Bands[0].Columns[0].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox; ugProcedures.DisplayLayout.Bands[0].Columns[0].DataType = System.Type.GetType("System.Byte[]"); // true.GetType(); ugProcedures.DisplayLayout.Bands[0].Columns[0].Header.Caption = "Delete"; ugProcedures.DisplayLayout.Bands[0].Columns[0].Header.VisiblePosition = 0; Infragistics.Win.EmbeddableImageRenderer imgEditor = new Infragistics.Win.EmbeddableImageRenderer(); Bitmap bmpCellImage = Properties.Resources.deleteButton; imgEditor.DefaultImage = bmpCellImage; imgEditor.ScaleImage = Infragistics.Win.ScaleImage.Never; //imgEditor.ScaleImage = Infragistics.Win.ScaleImage.Always; ugProcedures.DisplayLayout.Bands[0].Columns[0].Editor = imgEditor; } else { if (ugProcedures.DisplayLayout.Bands[0].Columns["Delete"].Header.VisiblePosition != 0) { ugProcedures.DisplayLayout.Bands[0].Columns["Delete"].Header.VisiblePosition = 0; } ugProcedures.DisplayLayout.Bands[0].Columns[0].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox; //ugProcedures.DisplayLayout.Bands[0].Columns[0].DataType = true.GetType(); ugProcedures.DisplayLayout.Bands[0].Columns[0].Header.Caption = "Delete"; ugProcedures.DisplayLayout.Bands[0].Columns[0].Hidden = false; }
Thanks in Advance.
Scott.
Thanks for the response. I understand written communications can be difficult to interpret. My main complaint is an increasing trend on these forums of failing to offer code snippets. Your code snippet was more than I was looking for and is greatly appreciated. It's a way of solving the problem I would not have thought of. When the object model is an complex as it is and the lack of more than rudemental code examples in the documentation, code snippets can be the only way for some people to wrap their minds around the model. Below is how I solved the problem. It appears to work and I have not be able to achive a failure mode, yet.
switch (attach){ case true: row.Cells["AttachmentsIcon"].Appearance.ImageBackground = GridIcons.Images[0]; break; case false: row.Cells["AttachmentsIcon"].Appearance.ImageBackground = null; break; default: break;}
Hi,
Sometimes it's easy to mis-read the tone of a forum post, and I think maybe that has happened here. Nothing I said here was intended as a critique of your code. I was just trying to explain why what you have here was not working.
I can totally understand how the code you have here seems like it should work, and this is not the first time I have seen someone attempt to do the same thing and wonder why it doesn't work. So the confusion here seems to be a result of our object model.
Anyway, it's not clear to me if you are displaying images in every cell of the column or cells in this column. But assuming that this is a dedicated Image column, here's what I would do to make this work in the most efficient way:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; UltraGridBand band = layout.Bands[0]; // Create an Appearance with the TRUE image. Infragistics.Win.Appearance attachmentAppearance = layout.Appearances.Add("Attachment"); attachmentAppearance.ImageHAlign = HAlign.Center; attachmentAppearance.Image = myImage; // Add an unbound column to display the true or false images. UltraGridColumn column = band.Columns.Add("AttachmentsIcon"); column.CellActivation = Activation.ActivateOnly; } private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { Infragistics.Win.UltraWinGrid.UltraGridRow row = e.Row; bool attach = (bool)row.GetCellValue("Boolean 1"); switch (attach) { case true: row.Cells["AttachmentsIcon"].Appearance = row.Band.Layout.Appearances["Attachment"]; break; case false: row.Cells["AttachmentsIcon"].Appearance = null; break; default: break; } }
I have complained about this issue on the customer service surveys and have no way of sending this directly so you are getting my reply via the forum. You do a good job at finding flaws in code, but I see little in actual code examples you have posted to help people. Yes the code had redundant lines. I have been trying to get something to work and gave you the code "as is" for assistance, not a code critique. Additionally, I found the problem and fixed it, but I had to go to a non-Infragistics site to get real help for your product. Don't get me wrong. The product is very good and very powerful. It is the support side of the house that is lacking.
Hi Bob,
This code doesn't work because you are doing two separate, contradictory, things.
Setting the Style of the column to Image makes the cell display it's Value as an image. But your unbound cell probably has no value.
The Appearance.Image property applies an image to a cell that contains some other value already. The Image Style on a column already display the cell's Value as an image, so it doesn't really make sense for that cell to also display the cell's appearance as an additional image.
By the way, you are setting the Style on the cell in both cases, so that's a bit redundant. It would be a lot more efficient to set the Style on the entire column in the InitializeLayout event of the grid. At the same point, you could also set the DataType on the column to Image. Then you could set the Value of the cell in InitializeRow.
Mike,
I am having an issue with the gridview also. I have a column that is bound to a boolean to know if the row has attached files. I have another column that is unbound. in the "InitializeRow" event I am testing for the boolean. if true display a paperclip image, else do nothing to the unbound column/cell. I renders without error, but the image does not appear. Now here is where the fun begins. I have a document exporter wired to send the grid to a pdf or xps. If I export it to either of those, the image shows on the export. Code snipper below...
private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { Infragistics.Win.UltraWinGrid.UltraGridRow row = e.Row; . . . bool attach = (bool)row.Cells["Attachment"].Value; . . . switch (attach) { case true: row.Cells["AttachmentsIcon"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Image; row.Cells["AttachmentsIcon"].Appearance.Image = GridIcons.Images[0]; break; case false: row.Cells["AttachmentsIcon"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Image; row.Cells["AttachmentsIcon"].Appearance.Image = null; break; default: break; }}
Any help is appreciated
Bob