Click here to Skip to main content
15,912,578 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: regarding datagrid Pin
mcgann20-Dec-05 23:59
mcgann20-Dec-05 23:59 
QuestionXML utf-16 encoding Pin
Marc Soleda20-Dec-05 3:21
Marc Soleda20-Dec-05 3:21 
QuestionEvent is captured in project but not when referenced Pin
Fawxes20-Dec-05 2:47
Fawxes20-Dec-05 2:47 
AnswerRe: Event is captured in project but not when referenced Pin
Fawxes20-Dec-05 12:43
Fawxes20-Dec-05 12:43 
QuestionHow to return the X, Y position of a particular cell in Listview? Pin
Rachel Lam19-Dec-05 22:34
Rachel Lam19-Dec-05 22:34 
AnswerRe: How to return the X, Y position of a particular cell in Listview? Pin
Dean_SF20-Dec-05 11:18
Dean_SF20-Dec-05 11:18 
GeneralRe: How to return the X, Y position of a particular cell in Listview? Pin
Rachel Lam20-Dec-05 20:37
Rachel Lam20-Dec-05 20:37 
GeneralRe: How to return the X, Y position of a particular cell in Listview? Pin
Dean_SF21-Dec-05 4:44
Dean_SF21-Dec-05 4:44 
Oh yes, I should have included that.

In the MouseDown event you have the coordinates of the mouse which you can use to determine which column the user clicked in. When I subclassed the listview, I added this:

Private _subitemClicked As Integer
Private li As ListViewItem
Private oldLI As ListViewItem
Private strOriginalText As String

Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
Dim X As Integer = 0
Dim Y As Integer = 0
oldLI = li

li = Me.GetItemAt(e.X, e.Y)
X = e.X
Y = e.Y

'Determine the subitem clicked.
If Not li Is Nothing Then
Dim nStart As Integer = X
Dim liBounds As Rectangle = li.GetBounds(ItemBoundsPortion.Entire)
Dim i As Integer
Dim spos As Integer = liBounds.X

For i = 0 To Me.Columns.Count - 1
If nStart >= spos And nStart < (spos + Me.Columns(i).Width) Then
'We found the subitem they indicated.
_subitemClicked = i
Exit For
End If
spos += Me.Columns(i).Width
Next
End If

'Now call any custom code the developer may have added behind the form.
MyBase.OnMouseDown(e)
End Sub

I then added a property which returned the subitem clicked:

<browsable(false), description("gets="" the="" zero-based="" index="" of="" column="" clicked."),="" _
="" category("appearance")=""> _
Public ReadOnly Property SubitemClicked() As Integer
Get
Return _subitemClicked
End Get
End Property

So when you need to display a textbox you can use the Click event:

Private Sub lvwLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvwLeft.Click

Me.lvwLeft.ShowTextBox(Me.lvwLeft.SelectedItems(0), Me.lvwLeft.SubitemClicked)

End Sub

Now you need a way to transfer the contents of the textbox back to the listview cell. First add this line to the ShowTextBox method right after the editBox.Show() line:

strOriginalText = subItemText.Trim

Add these lines globally to your subclassed listview:

Private bolSkipUpdate As Boolean = False
Public Event ListviewItemChanged(ByVal item As ListViewItem, ByVal subitem As Integer)

Now add these routines:



Private Sub editBox_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles editBox.KeyUp

If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab Then
li.SubItems(subItemSelected).Text = editBox.Text
editBox.Hide()
End If

If e.KeyCode = Keys.Escape Then
bolSkipUpdate = True
editBox.Hide()
bolSkipUpdate = False
End If
End Sub

Private Sub editBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles editBox.LostFocus
If Not bolSkipUpdate Then
oldLI.SubItems(subItemSelected).Text = editBox.Text
If strOriginalText <> editBox.Text Then
RaiseEvent ListviewItemChanged(oldLI, subItemSelected)
End If
editBox.Hide()
End If
End Sub

Now, whenever the contents of the textbox are changed and committed to the listview, the ListviewItemChanged event will get raised so you can write custom code to handle it.

Ideally, you want to subclass the listview and include all this code. Otherwise you'll have to duplicate it for every instance of your listview.

Dean
GeneralRe: How to return the X, Y position of a particular cell in Listview? Pin
Rachel Lam21-Dec-05 15:27
Rachel Lam21-Dec-05 15:27 
Questiongenerating file from dll to client machine Pin
uktrips00719-Dec-05 22:30
uktrips00719-Dec-05 22:30 
AnswerRe: generating file from dll to client machine Pin
Dave Kreskowiak20-Dec-05 2:50
mveDave Kreskowiak20-Dec-05 2:50 
Questionip not reachable Pin
nandhusivakumar19-Dec-05 21:46
nandhusivakumar19-Dec-05 21:46 
AnswerRe: ip not reachable Pin
Mekong River19-Dec-05 22:52
Mekong River19-Dec-05 22:52 
AnswerRe: ip not reachable Pin
Colin Angus Mackay19-Dec-05 23:35
Colin Angus Mackay19-Dec-05 23:35 
AnswerRe: ip not reachable Pin
Dave Kreskowiak20-Dec-05 4:53
mveDave Kreskowiak20-Dec-05 4:53 
QuestionHow to display a chm file in visual basic application Pin
tsnarayanan19-Dec-05 19:57
tsnarayanan19-Dec-05 19:57 
AnswerRe: How to display a chm file in visual basic application Pin
MyNothing19-Dec-05 20:02
MyNothing19-Dec-05 20:02 
AnswerRe: How to display a chm file in visual basic application Pin
S Douglas19-Dec-05 21:40
professionalS Douglas19-Dec-05 21:40 
AnswerRe: How to display a chm file in visual basic application Pin
S Douglas20-Dec-05 1:10
professionalS Douglas20-Dec-05 1:10 
Questioncreating EXCEL file fro VB Pin
Paritos19-Dec-05 19:56
Paritos19-Dec-05 19:56 
AnswerRe: creating EXCEL file fro VB Pin
MyNothing19-Dec-05 20:26
MyNothing19-Dec-05 20:26 
GeneralRe: creating EXCEL file fro VB Pin
Mekong River19-Dec-05 22:58
Mekong River19-Dec-05 22:58 
QuestionBeginner's Program Pin
I am the one; I am genius19-Dec-05 17:47
I am the one; I am genius19-Dec-05 17:47 
AnswerRe: Beginner's Program Pin
Steve Pullan19-Dec-05 17:52
Steve Pullan19-Dec-05 17:52 
GeneralRe: Beginner's Program Pin
MyNothing19-Dec-05 17:59
MyNothing19-Dec-05 17:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.