I am converting a MS Access application to VB.NET 2005 with IG 2008.2.2121. On one of the existing forms in Access, there is a grid with a column that displays a document link icon. The user can either open that file or choose a new file to link to. Access handles all of this natively without much code required. However, I am having some issues trying to figure out how to implement the same sort of behavior in our new application. First of all, the field that should display the document link shows up as follows:
How do I tell the WinGrid to display it as a document link? The datatype in the Sql table is Image. Also, if there isn't a file stored, how would I be able to implement the open file dialog so that the user could choose the file to link to?
I would greatly appreciate any assistance you could provide,~Kelly
My workaround:
1. Changed the data in the SQL table to string and stored the UNC path of the file. 2. Added an image column to the datatable. 3. On initialize row, if the File_Path column is not empty, display the image. 4. Then I used the mouseclick event to catch the rightclick, grabbed the UIElement to see if it was the Image column, then displayed a custom context menu.
Here's some of the code:
Private Sub Form1_Load With Me .File_DataTable = PopulateViewableTable(.FillSqlString) .File_DataTable.Columns.Add("Img", GetType(Image)) .File_Grid.DataSource = .File_DataTable End WithEnd SubPrivate Sub File_Grid_InitializeRow With e.Row Dim CellVal = .GetCellValue(.Band.Columns("File Path")) If (Not CellVal Is DBNull.Value) AndAlso (Not CellVal = "") Then .Cells("PB").Value = My.Resources.FileIcon Else .Cells("PB").Value = DBNull.Value End If End WithEnd SubPrivate Sub File_Grid_MouseClick If e.Button = Windows.Forms.MouseButtons.Right Then Dim MousePoint As Point = New Point(e.X, e.Y) Dim element As UIElement = CType(sender, UltraGrid).DisplayLayout.UIElement.ElementFromPoint(MousePoint) Dim CellClicked As UltraGridCell = CType(element.GetContext(GetType(UltraGridCell)), UltraGridCell) If Not CellClicked Is Nothing AndAlso CellClicked.Column.Key = "PB" Then Me.RowDataToUse = CellClicked.Row.ListObject Me.Create_ContextMenu(Me.RowDataToUse.Item("File Path").ToString) Me.GridContextMenu.Show(Me.File_Grid, MousePoint) End If End IfEnd Sub
Here are my resources:
1. Getting the UIElement from the MouseClick:http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=84832. Custom Context Menu:http://www.codeproject.com/KB/cpp/ContextMenuVBNET.aspx3. Getting a UNC Path for a Shared Drive:http://forums.asp.net/t/1394855.aspx?PageIndex=1
Thanks Mike
Hi Kelly,
Since the cell is showing "Byte[]", it means that the data in that cell is a Byte array. This is how images are typically stored in a database - as a byte array.
The EmbeddableImageRenderer will attempt to convert the Byte array into an image.
But in this case, I'm guessing that your data contains more than just an image. You mentioned a Linked_Record, which I assume includes more than just an image. It probably also includes other information.
If that's the case, then there is no way the grid can extract the image or other information from the Byte array. The grid has no way of knowing how to do that.
It might be possible for you to do it in your code, but that's something you would need to explore with Microsoft.
Hi Brian and Mike,
I tried both options in initialize layout but had the same result - blank cells.
.Columns("Linked_Record").Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Image .Columns("Linked_Record").Editor = New Infragistics.Win.EmbeddableImageRenderer()
If you have any other suggestions I would grealy appreciate it!
Thanks,Kelly
I'm not familiar with linked records. So I'm not sure exactly what behavior you want from the cell.
If the data is stored as an image, then you probably just have to set the column's Style property to Image. I would recommend doing this in the InitializeLayout event of the grid.
e.Layout.Bands[0].Columns["Linked_Record"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Image;
To trap when the user clicks on the image, you should use the grid's MouseUp event and determine the cell based on the mouse position. Here's a KB article that shows you how to do this:
HOWTO:UltraWinGrid Mouse Position and Cell Identification