edit – Owl's Blog on .NET development http://www.componentowl.com/blog Component Owl codes Better ListView control all night so you don't have to. Tue, 04 Sep 2018 13:10:05 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.8 Custom label edit: How to rename file names without extension in Better ListView http://www.componentowl.com/blog/custom-label-edit-how-to-rename-file-names-without-extension-in-better-listview/ http://www.componentowl.com/blog/custom-label-edit-how-to-rename-file-names-without-extension-in-better-listview/#respond Thu, 20 Dec 2012 17:42:14 +0000 http://www.componentowl.com/blog/?p=831

Let’s suppose you want to display files with extensions in Better ListView, but allow user to rename just the file name, leaving the file extension intact after the editing.

The code for this is very simple. Just turn on label editing and handle two events: BeforeLabelEdit and AfterLabelEditCancel:

C#

[csharp gutter=”false” toolbar=”false”]
betterListView.LabelEdit = true;

betterListView.BeforeLabelEdit += BetterListViewBeforeLabelEdit;
betterListView.AfterLabelEditCancel += BetterListViewAfterLabelEditCancel;

void BetterListViewBeforeLabelEdit(object sender, BetterListViewLabelEditCancelEventArgs eventArgs)
{
string labelOriginal = eventArgs.Label;

// keep only file name in the modified label
string labelNew = Path.GetFileNameWithoutExtension(labelOriginal);

eventArgs.Label = labelNew;
}

void BetterListViewAfterLabelEditCancel(object sender, BetterListViewLabelEditCancelEventArgs eventArgs)
{
string labelOriginal = eventArgs.Label;

// add extension when editing is complete
string labelNew = String.Concat(
labelOriginal,
Path.GetExtension(eventArgs.SubItem.Text));

eventArgs.Label = labelNew;
}
[/csharp]

Visual Basic

[vb gutter=”false” toolbar=”false”]
BetterListView.LabelEdit = True

AddHandler Me.betterListView.BeforeLabelEdit, AddressOf BetterListViewBeforeLabelEdit
AddHandler Me.betterListView.AfterLabelEditCancel, AddressOf BetterListViewAfterLabelEditCancel

Private Sub BetterListViewBeforeLabelEdit(sender As Object, eventArgs As BetterListViewLabelEditCancelEventArgs)
Dim labelOriginal As String = eventArgs.Label

‘ keep only file name in the modified label
Dim labelNew As String = Path.GetFileNameWithoutExtension(labelOriginal)

eventArgs.Label = labelNew
End Sub

Private Sub BetterListViewAfterLabelEditCancel(sender As Object, eventArgs As BetterListViewLabelEditCancelEventArgs)
Dim labelOriginal As String = eventArgs.Label

‘ add extension when editing is complete
Dim labelNew As String = [String].Concat(labelOriginal, Path.GetExtension(eventArgs.SubItem.Text))

eventArgs.Label = labelNew
End Sub
[/vb]

Naturally, this feature can be used not only for file names, but whenever you would like to edit different view on the data then the displayed one.

Full version of Better ListView supports even custom embedded editing controls and you have complete control over the label editing process.

]]>
http://www.componentowl.com/blog/custom-label-edit-how-to-rename-file-names-without-extension-in-better-listview/feed/ 0
Customize Label Editing (Embedded) Control for Each Line in Better ListView http://www.componentowl.com/blog/customize-label-editing-embedded-control-for-each-line-in-better-listview/ http://www.componentowl.com/blog/customize-label-editing-embedded-control-for-each-line-in-better-listview/#comments Wed, 04 Apr 2012 10:33:49 +0000 http://www.componentowl.com/blog/?p=771 Embedded controls for label edit in Better ListView can be customized not only for every column, but even for every row.

This is not a new feature, but would be nice to mention that you can possibly have a different custom editing control for every cell…

C#

[csharp gutter=”false” toolbar=”false”]
private IBetterListViewEmbeddedControl ListViewRequestEmbeddedControl(object sender, BetterListViewRequestEmbeddedControlEventArgs eventArgs)
{
// show editing controls in the second column
if (eventArgs.SubItem.Index == 1)
{
// show my custom control on the first row
if (eventArgs.SubItem.Item.Index == 0)
{
return (new DocumentAccessConrol());
}

// show my custom control on the second row
if (eventArgs.SubItem.Item.Index == 1)
{
return (new BetterListViewComboBoxEmbeddedControl());
}

// show my custom control on the third row
if (eventArgs.SubItem.Item.Index == 2)
{
return (new BetterListViewTextBoxEmbeddedControl());
}
}

return null;
}
[/csharp]

 

Visual Basic

[vb gutter=”false” toolbar=”false”]
Private Function ListViewRequestEmbeddedControl(ByVal sender As Object, ByVal eventArgs As BetterListViewRequestEmbeddedControlEventArgs) _
As IBetterListViewEmbeddedControl

‘ show editing controls in the second column
If eventArgs.SubItem.Index = 1 Then

‘ show my custom control on the first row
If eventArgs.SubItem.Item.Index = 0 Then
Return (New DocumentAccessConrol())
End If

‘ show my custom control on the second row
If eventArgs.SubItem.Item.Index = 1 Then
Return (New BetterListViewComboBoxEmbeddedControl())
End If

‘ show my custom control on the third row
If eventArgs.SubItem.Item.Index = 2 Then
Return (New BetterListViewTextBoxEmbeddedControl())
End If

End If

Return Nothing

End Function
[/vb]

 

And there is the result:

Custom Embedded Control on the First Line

Custom Embedded Control on the First Line

 

TextBox Control on the Third Line

TextBox Control on the Third Line

]]>
http://www.componentowl.com/blog/customize-label-editing-embedded-control-for-each-line-in-better-listview/feed/ 2