|
I am having a problem dragging and dropping into a datagrid. I have the code, and it works for certain cells in the datagrid, but items that are dates or integers (as opposed to strings) the hittest does not work. Here's the code:
Private Sub DataGrid1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGrid1.DragDrop Dim lbl As String = DirectCast(e.Data.GetData(GetType(String)), String) Dim Index As Integer TextBox1.Text = lbl DataGrid1.BorderStyle = BorderStyle.Fixed3D Dim pt As Point = DataGrid1.PointToClient(New Point(e.X, e.Y)) Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(pt.X, pt.Y) hitRow = hti.Row hitCol = hti.Column If hti.Type = DataGrid.HitTestType.Cell Then DataGrid1(hti.Row, hti.Column) = lbl End If Label6.Text = hitRow Label7.Text = hitCol Label9.Text = Me.DataGrid1(hti.Row, 8).ToString() End Sub
Any ideas?
|
|
|
|
|
Sorry about the code formatting. Here it is (it wouldn't let me edit it)
Private Sub DataGrid1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGrid1.DragDrop
Dim lbl As String = DirectCast(e.Data.GetData(GetType(String)), String)
Dim Index As Integer
TextBox1.Text = lbl
DataGrid1.BorderStyle = BorderStyle.Fixed3D
Dim pt As Point = DataGrid1.PointToClient(New Point(e.X, e.Y))
Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(pt.X, pt.Y)
hitRow = hti.Row
hitCol = hti.Column
If hti.Type = DataGrid.HitTestType.Cell Then
DataGrid1(hti.Row, hti.Column) = lbl
End If
Label6.Text = hitRow
Label7.Text = hitCol
Label9.Text = Me.DataGrid1(hti.Row, 8).ToString()
End Sub
|
|
|
|
|
Hi,
Phantom715 wrote: DirectCast(e.Data.GetData(GetType(String)), String)
so you are accepting a string
Phantom715 wrote: DataGrid1(hti.Row, hti.Column) = lbl
and storing it in a cell; what if the cell isn't expecting a string? shouldn't you parse numbers, dates, etc.?
|
|
|
|
|
Okay, I guess I wasn't specific enough. I don't necessarily need it to put anything in the datagrid (although that would be nice to know for future purposes ). I need to automatically recognize which row the item was dropped onto. When the datatype in the cell doesn't match what is being dropped, it doesn't perform the hittest. (I think )
|
|
|
|
|
OK, so use the row and/or column number to decide whether you want to drop the string,
add the result of such tests to the line If hti.Type = DataGrid.HitTestType.Cell .
That should take care of it.
BTW: sounds like you must do the same in DragEnter/DragOver handlers to get correct UI behavior.
|
|
|
|
|
Awesome, thanks! The DragEnter/Dragover was what I needed! All I did was enter the hittest into both of those subs, and it recognizes now. Thank you very much.
|
|
|
|
|
You're welcome.
|
|
|
|
|
Is it possible to create an instance of a managed object without containing a reference to the same object (using VB 2005)?
Normally, you would add references to various .dlls and then create objects based on the references.
Is it possible to create objects from .dlls that are not referenced by the project? The .dlls in question are managed objects, so I don't think CreateInstance will work since that is for COM objects.
Any pointers or general guidance on what to look for would be helpful. Thanks!
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Look at LoadAssembly
We called our routines CreateInstance but there's 3 flavors. by default it looks local/gac. but you can specify a location.
Public Shared Function CreateInstance(ByVal sFullClassName As String) As Object
Dim ao As [Assembly], aoName As New AssemblyName
Dim o As Object
Try
aoName.Name = sFullClassName.Substring(0, sFullClassName.LastIndexOf("."))
ao = [Assembly].Load(aoName)
o = ao.CreateInstance(sFullClassName, True)
Catch ex As Exception
Try
ExceptionManager.HandleClientException("Exception creating an instance of " & sFullClassName & ".", ex)
Catch : End Try
Throw ex
End Try
ao = Nothing
Return o
End Function
Public Shared Function CreateInstance(ByVal sAssembly As String, ByVal sClass As String) As Object
Dim ao As [Assembly], aoName As New AssemblyName
Dim o As Object
Try
aoName.Name = sAssembly
ao = [Assembly].Load(aoName)
o = ao.CreateInstance(sAssembly & "." & sClass, True)
Catch ex As Exception
'ExceptionManager.PublishException(ex)
Throw ex
End Try
ao = Nothing
Return o
End Function
Public Shared Function CreateInstance(ByVal sFullPathIncludingFileName As String, ByVal sAssembly As String, _
ByVal sClass As String) As Object
Dim ao As [Assembly], o As Object
Try
ao = [Assembly].LoadFrom(sFullPathIncludingFileName)
o = ao.CreateInstance(sAssembly & "." & sClass, True)
Catch ex As Exception
'ExceptionManager.PublishException(ex)
Throw ex
End Try
ao = Nothing
Return o
End Function
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
modified on Tuesday, December 9, 2008 1:57 PM
|
|
|
|
|
That's exactly what I am trying to do.
Next dumb question:
So once the obj is created, how do you call the object's methods? Are you using a directcast with another method of the ao object?
Nevermind, I think i got it figured out (create type, methodinfo, call method etc).
Thanks for the guidance!
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
modified on Tuesday, December 9, 2008 2:54 PM
|
|
|
|
|
Actually - when you do a loadassembly you don't have to use reflection any longer. It is the same as saying Dim MyObj as new Test. Once you have the object that is returned just access it's properties/fields/methods as before like it was referenced.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
nlarson11 wrote: Actually - when you do a loadassembly you don't have to use reflection any longer. It is the same as saying Dim MyObj as new Test. Once you have the object that is returned just access it's properties/fields/methods as before like it was referenced.
Sigh........you are correct.
Turning Option Strict Off allows me to this now. I am so used to always have Option Strict/Explicit set that I forget about the consequences sometimes.
Thanks for the help!
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Hello All,
I am developing a MDI application in vb.net 3.5
but I am fecing a problem a when i am pressing "Ctl" + "Tab" button of the keyboard.
As I open all the child form in maximise mode so, I do not want to press "Ctl+Tab" to suffle the childform
So, How can I stop that in my application.
Arindam Banerjee
Sr. Software Developer
Rance Computer Pvt Ltd.
Kolkata (India)
|
|
|
|
|
I've never turned the thing off myself, so, this may not work.
But, I'd start by turning Keypreview on the MdiParent form on, then handle it's KeyDown event and eat the Tab key if Ctrl is being held down.
|
|
|
|
|
Please let me know the property with which I can accomplish the above mentioned task.
For more clearity here is an example:
Suppose I have a combobox with name- cboProject
and my Two strings are - Puneet, India
DesiredTask: I want to add both these strings to 0th Index of cboProject and at the same point of time hide the text followed by "," i.e hide India.
Thanks & Regards
Puneet
|
|
|
|
|
oh dear god... try attempting it before you ask!
string3 = string1 + string2
|
|
|
|
|
GriffinPeter wrote: oh dear god... try attempting it before you ask!
string3 = string1 + string2
That's not really what the OP is asking, I think
|
|
|
|
|
Puneet Bhatnagar wrote: DesiredTask: I want to add both these strings to 0th Index of cboProject and at the same point of time hide the text followed by "," i.e hide India.
You would have to create a multi-column combo box for this. A simple search brings me to this[^] article on CP.
|
|
|
|
|
If you only need two columns and one will always be hidden you could try the following:
create a datatable with 2 columns
fill the datatable with the data you want
assing the datatable to the cboproject.datasource property
assing the cboproject.valuemember property to the columnname from the column to be hidden
assing the cboproject.displaymember to the columnname from the column to be shown
The multi column combobox mentioned by ChandraRam could give you more options tho.
|
|
|
|
|
Hi,
Thanks for your help and time. However still I am facing some problem. Please find below my code.
Try
Dim sql As String
Dim DB2conn As DB2Connection
Dim ds As New DataSet
DB2conn = New DB2Connection("server=" & ServerAddress & ";database= " & sDBName & ";Connect Timeout=30;user Id=" & UName & ";password =" & pwd &)
Dim DB2Cmd As New DB2Command
sql = "Select * from ProjectMaster"
DB2conn.Open()
Dim DB2DA As New DB2DataAdapter(sql, DB2conn)
DB2Cmd = New DB2Command(sql, DB2conn, DB2trans)
DB2DA.Fill(ds)
ComboBox2.DataSource = ds.Tables(0)
ComboBox2.DisplayMember = "ProjectMaster.ReleaseNumber"
<b>Me.ComboBox2.ValueMember = "ProjectMaster.ProjectID"</b>
Catch ex As Exception
MessageBox.Show(ex.Message + " " + ex.Source)
Finally
DB2conn.Close()
End Try
The code is breaking at line (ComboBox2.ValueMember = "ProjectMaster.ProjectID"), in bold in code snippet. Please let me know where I am going wrong.
Again Thanks for your efforts.
|
|
|
|
|
First a Select * isn't adviced (but is not the cause of the error)
You don't need to use the tablename before the columname I'm not shure but I think that is what causing the problem (the combobox can't find that column) so try changing the line to :
me.combobox2.displaymember = "ReleaseNumber"
me.combobox2.valuemember = "ProjectID"
If that doesn't help make shure the datatable has these 2 columns (debug and visualy confirm it) with the correct names
|
|
|
|
|
Hi,
I tried with all your suggestions however it is still not working. Please let me know what shall I do?
Thanks & regards
Puneet
|
|
|
|
|
what is the error message you are getting?
|
|
|
|
|
"Could Not Bind To The New Display Member,
Parameter Name: New Display Member"
|
|
|
|
|
If you use string3 = string1 + string2 you won't be able to hide the second string.
You need to put the strings into an object that has two fields and add this object to the ComboBox. You could then use the DisplayMember property to show only the first field. Alternatively, you could override the ToString() function to display only the first field.
Something like the following should do it.
Public Class TheData
'Public for simplicity but should be properties
Public firstString As String
Public secondString As Sting
Public Overrides Function ToString() As String
return firstString
End Function
End Class
In your code to populate the combobox you would need something like this.
Dim d As TheData = new TheData()
d.firstString = "Puneet"
d.secondString = "India"
me.cboProject.Items.Insert(0, d) ' or me.cboProject.Items.Add(d)
There might be an easier way but I can't think of one (it's a breeze in MS Access because the combobox control has multiple columns that you can show or hide.)
David Rice
|
|
|
|