How to make the first column display line number?
I guess it should have the following features:
1. it should not be included in the data model
2. it automatically maintains 1.2.3... values when the rows are reordered
Any suggestions?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry the above code should have used DisplayIndex, not RowIndex. DisplayIndex
will always give the correct line number, even when the control is grouped.
I found this thread searching for the problem that for some OLVs the first column does not get filled with the number. I have several OLVs with the same settings in my project and for only a few it is not working.
The event fires and right after the instruction, the Text of the SubItem is correct. But some time after it get cleared again. Have you any idea why this is caused?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That code should always work. The FormatCell should be triggered every time a ListViewItem is built/rebuilt, and there should be no other way to change the contents of the ListViewItem.
It is always possible that there is some bug in my code that makes it not work correctly :)
Can you narrow down the steps that occur to make the values disappear?
Regards,
Phillip
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have the exact problem. To narrow it down I'll say I only have the problem on the first column. When SubItem index is set to any column number, its OK and row number will be shown. However on the first subitem this does not work. Here is my code:
protected override void OnFormatRow(FormatRowEventArgs args)
{
base.OnFormatRow(args);
if (mAutoIndexRow)
args.Item.SubItems[0].Text = args.DisplayIndex.ToString(); // This does not work
args.Item.SubItems[1].Text = args.DisplayIndex.ToString(); // This works
}
PS: I have tested the code on an event handler too. No difference between a handler and overriden method.
Last edit: Klaus 2014-07-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
How to make the first column display line number?
I guess it should have the following features:
1. it should not be included in the data model
2. it automatically maintains 1.2.3... values when the rows are reordered
Any suggestions?
Thanks.
Listen for the FormatRow event and set the text of the subitem that you want
to contain line number.
Sorry the above code should have used DisplayIndex, not RowIndex. DisplayIndex
will always give the correct line number, even when the control is grouped.
Hi, sorry to be a gravedigger.
I found this thread searching for the problem that for some OLVs the first column does not get filled with the number. I have several OLVs with the same settings in my project and for only a few it is not working.
The event fires and right after the instruction, the Text of the SubItem is correct. But some time after it get cleared again. Have you any idea why this is caused?
Thanks
That code should always work. The
FormatCell
should be triggered every time aListViewItem
is built/rebuilt, and there should be no other way to change the contents of theListViewItem
.It is always possible that there is some bug in my code that makes it not work correctly :)
Can you narrow down the steps that occur to make the values disappear?
Regards,
Phillip
I have the exact problem. To narrow it down I'll say I only have the problem on the first column. When SubItem index is set to any column number, its OK and row number will be shown. However on the first subitem this does not work. Here is my code:
protected override void OnFormatRow(FormatRowEventArgs args)
{
base.OnFormatRow(args);
if (mAutoIndexRow)
args.Item.SubItems[0].Text = args.DisplayIndex.ToString(); // This does not work
args.Item.SubItems[1].Text = args.DisplayIndex.ToString(); // This works
}
PS: I have tested the code on an event handler too. No difference between a handler and overriden method.
Last edit: Klaus 2014-07-15
This 2nd post was not correct. I decided to delete it but I could not find the delete button! The above post is the only correct one.
Last edit: Klaus 2014-07-15