burak Posted April 12, 2004 Posted April 12, 2004 Hello, Is it possible to use a class written in C# in a vb.net winforms app? If it is, how do we do it? Thank you, Burak Quote
Administrators PlausiblyDamp Posted April 12, 2004 Administrators Posted April 12, 2004 Through Visual Studio it isn't directly possible. You could compile the C# class into a classlibrary and then reference this from you VB app though. Alternatively if you are building things from the command line you could compile the C# file to a module and then link this to your VB app. details here Out of interest what does this class do? It may be easy to convert to VB either manually or through a service like this one Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
burak Posted April 12, 2004 Author Posted April 12, 2004 Hello, This class creates a datagrid with a hyperlink column. From http://www.developersdex.com/vb/message.asp?r=4079310&p=1120 using System; using System.Data; using System.Drawing; using System.Windows.Forms; namespace MyColumnStyles { /// <summary> /// Summary description for LinkLabelColumnStyle. /// </summary> public class LinkLabelColumnStyle : DataGridTextBoxColumn { #region Variables private DataLinkLabel columnLinkLabel; #endregion #region Properties public LinkLabel LinkLabel { get { return this.columnLinkLabel; } } #endregion #region Constructor public LinkLabelColumnStyle() { this.columnLinkLabel = new DataLinkLabel(); this.columnLinkLabel.Click += new EventHandler(ColumnLinkLabel_Click); } #endregion #region Edit protected override void Edit(CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible) { base.Edit(source,rowNum,bounds,readOnly,instantText,cellIsVisible); this.columnLinkLabel.Parent = this.TextBox.Parent; this.columnLinkLabel.Location = this.TextBox.Location; this.columnLinkLabel.Size = new Size(this.TextBox.Width,this.TextBox.Height); this.TextBox.Visible = false; this.columnLinkLabel.Text = this.TextBox.Text; this.columnLinkLabel.Visible = true; this.columnLinkLabel.BringToFront(); this.columnLinkLabel.Focus(); } #endregion private void ColumnLinkLabel_Click(object sender, EventArgs e) { MessageBox.Show("WooHoo"); } } public class DataLinkLabel : LinkLabel { private int WM_KEYUP = 257; protected override void WndProc(ref Message m) { if (m.Msg == WM_KEYUP) { return; } base.WndProc (ref m); } } } I used the vb.net translator you provided and modified the resulting code and ended up with this Imports System Imports System.Data Imports System.Drawing Imports System.Windows.Forms Namespace MyColumnStyles Public Class LinkLabelColumnStyle Inherits DataGridTextBoxColumn Private columnLinkLabel As DataLinkLabel Public ReadOnly Property LinkLabel() As LinkLabel Get Return Me.columnLinkLabel End Get End Property Public Sub New() Me.columnLinkLabel = New DataLinkLabel AddHandler Me.columnLinkLabel.Click, AddressOf ColumnLinkLabel_Click End Sub 'New Private Sub ColumnLinkLabel_Click(ByVal sender As Object, ByVal e As EventArgs) MsgBox(Me.columnLinkLabel.Text) MessageBox.Show("WooHoo") End Sub Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, ByVal read As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean) MyBase.Edit(source, rowNum, bounds, read, instantText, cellIsVisible) Me.columnLinkLabel.Parent = Me.TextBox.Parent Me.columnLinkLabel.Location = Me.TextBox.Location Me.columnLinkLabel.Size = New Size(Me.TextBox.Width, Me.TextBox.Height) Me.TextBox.Visible = False Me.columnLinkLabel.Text = Me.TextBox.Text Me.columnLinkLabel.Visible = True Me.columnLinkLabel.BringToFront() Me.columnLinkLabel.Focus() End Sub 'Edit Public Class DataLinkLabel Inherits LinkLabel Private WM_KEYUP As Integer = 257 Protected Overrides Sub WndProc(ByRef m As Message) If m.Msg = WM_KEYUP Then Return End If MyBase.WndProc(m) End Sub 'WndProc End Class 'DataLinkLabel End Class End Namespace 'MyColumnStyles I then used this code as follows Dim c0 As New MyColumnStyles.LinkLabelColumnStyle c0.TextBox.Text = "PROV_ID" c0.MappingName = "PROV_ID" c0.HeaderText = "ID" c0.Width = 45 Now there are 2 issues 1) The hyperlink only appears after you click on the cell. Is there a way for it to appear right from the start? 2) I want the page with the datagrid to disappear after the user clicks on a cell. Right now I am using this call Private Sub dtgResults_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dtgResults.MouseDown Dim str As String = "" ' get the value of the first cell (provider ID) ' when the user clicks on a row Dim hti As DataGrid.HitTestInfo hti = dtgResults.HitTest(e.X, e.Y) Try If hti.Type = DataGrid.HitTestType.Cell Or hti.Type = DataGrid.HitTestType.RowHeader Then str += dtgResults(hti.Row, 0).ToString() ' assign the provider ID to a global variable global_vars.PROVIDS = str 'MsgBox(global_vars.PROVIDS) End If Catch ex As Exception MsgBox(ex.Message) End Try If str <> "" Then 'Dim dgcs As DataGridColumnStyle = dtgResults.TableStyles(0).GridColumnStyles(dtgResults.CurrentCell.ColumnNumber) 'dtgResults.EndEdit(dgcs, dtgResults.CurrentCell.RowNumber, True) '' close the form 'Me.Close() Me.Dispose(False) End If End Sub I can't use this code anymore because it interferes with the hyperlink click. How can I close the form after the user clicks on the cell? Thank you, Burak Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.