/// <summary> /// OnMouseMove /// </summary> /// <remarks> /// shows tolltip for image columns. /// </remarks> /// <param name="e"></param> protected override void OnMouseMove(MouseEventArgs e) { // finds the point on the client side. HitTestInfo info = HitTest(e.X, e.Y); if (info.Type == HitTestType.Cell && (info.Row != tooltipSelectedRow || info.Column != tooltipSelectedColumn)) { DataGridImageColumn imageColumn = this.TableStyles[0].GridColumnStyles[info.Column] as DataGridImageColumn; if (imageColumn != null) { // forse redraw; imageToolTip.Active = false; imageToolTip.Active = true; } else { imageToolTip.Active = false; } tooltipSelectedRow = info.Row; tooltipSelectedColumn = info.Column; } base.OnMouseMove(e); }
/// <summary> /// Inits the DataGridTableStyle according to the types of the columns. /// </summary> /// <param name="tableStyle">table style</param> /// <param name="column">underline DataSource column</param> private void InitDataTableColumnAndStyle(DataGridTableStyle tableStyle, DataColumn column) { //if column's name starts with # - then user DataGridColumnStyle should be used. if (column.ColumnName[0] == TypeDelimiter) { string[] columnType = column.ColumnName.Split(TypeDelimiter); if (columnType[1] == DBViewerConstants.ImageColumnType) { DataGridImageColumn imageColumn = new DataGridImageColumn(); column.ColumnName = columnType[2]; SetDataTableColumnStyleProperties(tableStyle, imageColumn, column); } else if (columnType[1] == DBViewerConstants.BinaryColumnType) { DataGridBinaryColumn binaryColumn = new DataGridBinaryColumn(); column.ColumnName = columnType[2]; SetDataTableColumnStyleProperties(tableStyle, binaryColumn, column); EnableSave(binaryColumn); } } else { DataGridTextBoxColumn textBoxColumn = new DataGridTextBoxColumn(); SetDataTableColumnStyleProperties(tableStyle, textBoxColumn, column); EnableSave(textBoxColumn); } }
/// <summary> /// OnDoubleClick /// </summary> /// <remarks> /// 1. Shows the image from the DataSource in the <see cref="ImageViewer"/>. /// 2. If the ImageViewer requests to save the loaded image, saves it the DataSource. /// </remarks> /// <param name="e"></param> protected override void OnDoubleClick(EventArgs e) { base.OnDoubleClick(e); // finds the point on the client side. Point pt = this.PointToClient(Cursor.Position); // test the point HitTestInfo info = this.HitTest(pt); if (info.Type == HitTestType.Cell) { // if it is DataGridImageColumn (column that represents image) DataGridImageColumn style = this.TableStyles[0].GridColumnStyles[info.Column] as DataGridImageColumn; if (style != null && info.Row < ((DataTable)this.DataSource).Rows.Count) { ImageViewer imageViewer = new ImageViewer(); imageViewer.Image = ExtractImageFromDataSource(info.Row, info.Column); if (imageViewer.ShowDialog(this) == DialogResult.OK) { SaveImageToDataSource(imageViewer.Image, info.Row, info.Column); } imageViewer.Dispose(); } } }