When the comment is longer than the code
-
Five or six times longer...
/// <summary>
/// Gets and sets the selected indexes
/// </summary>
/// <remarks>
/// This is necessarily complicated.
/// Remember, the data comes from a DataTable (DT) - (or a list from which the DT data
/// was derived) and the outside world expects indexes to to relative to that DT.
/// But...we display the data in a DataGridView (DGV) via a DataView (DV) and apply
/// filtering and sorting to the DV according to the user input.
/// So the selected rows we get from the DGV are in last-selected-by-user order, (which
/// if fine and dandy), but are relative to the DGV rather than the underlying DV or
/// DT data source, as the DGV is subject to the sorting and filtering applied to the DV.
///
/// So, we get the selected items from the DGV (only place we can, the DV doesn't know
/// about selection), then have to convert that to the DataRow and get the index of that
/// from the DT. But (of course) the DGV returns a DataGridViewRow object just to be
/// annoying...
/// And that's just Get!
/// </remarks>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IEnumerable<int> SelectedIndexes
{
get { return dgvData.SelectedRows.Cast<DataGridViewRow>().Select(r => _DataSource.Rows.IndexOf(((DataRowView)r.DataBoundItem).Row)); }
set { ... }
}I almost wish I'd written it longhand instead of using Linq methods... :laugh:
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
Five or six times longer...
/// <summary>
/// Gets and sets the selected indexes
/// </summary>
/// <remarks>
/// This is necessarily complicated.
/// Remember, the data comes from a DataTable (DT) - (or a list from which the DT data
/// was derived) and the outside world expects indexes to to relative to that DT.
/// But...we display the data in a DataGridView (DGV) via a DataView (DV) and apply
/// filtering and sorting to the DV according to the user input.
/// So the selected rows we get from the DGV are in last-selected-by-user order, (which
/// if fine and dandy), but are relative to the DGV rather than the underlying DV or
/// DT data source, as the DGV is subject to the sorting and filtering applied to the DV.
///
/// So, we get the selected items from the DGV (only place we can, the DV doesn't know
/// about selection), then have to convert that to the DataRow and get the index of that
/// from the DT. But (of course) the DGV returns a DataGridViewRow object just to be
/// annoying...
/// And that's just Get!
/// </remarks>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IEnumerable<int> SelectedIndexes
{
get { return dgvData.SelectedRows.Cast<DataGridViewRow>().Select(r => _DataSource.Rows.IndexOf(((DataRowView)r.DataBoundItem).Row)); }
set { ... }
}I almost wish I'd written it longhand instead of using Linq methods... :laugh:
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
You just made my day lol
-
Five or six times longer...
/// <summary>
/// Gets and sets the selected indexes
/// </summary>
/// <remarks>
/// This is necessarily complicated.
/// Remember, the data comes from a DataTable (DT) - (or a list from which the DT data
/// was derived) and the outside world expects indexes to to relative to that DT.
/// But...we display the data in a DataGridView (DGV) via a DataView (DV) and apply
/// filtering and sorting to the DV according to the user input.
/// So the selected rows we get from the DGV are in last-selected-by-user order, (which
/// if fine and dandy), but are relative to the DGV rather than the underlying DV or
/// DT data source, as the DGV is subject to the sorting and filtering applied to the DV.
///
/// So, we get the selected items from the DGV (only place we can, the DV doesn't know
/// about selection), then have to convert that to the DataRow and get the index of that
/// from the DT. But (of course) the DGV returns a DataGridViewRow object just to be
/// annoying...
/// And that's just Get!
/// </remarks>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IEnumerable<int> SelectedIndexes
{
get { return dgvData.SelectedRows.Cast<DataGridViewRow>().Select(r => _DataSource.Rows.IndexOf(((DataRowView)r.DataBoundItem).Row)); }
set { ... }
}I almost wish I'd written it longhand instead of using Linq methods... :laugh:
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
Fantastic! I thought I was the only one who wrote comments like that. I feel so much relief! Thanks Griff.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
Fantastic! I thought I was the only one who wrote comments like that. I feel so much relief! Thanks Griff.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave KreskowiakI just know that in a years time I'm going to look at that line of code and go "What? Why?" :laugh: Perhaps I can head myself off at the pass!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
I just know that in a years time I'm going to look at that line of code and go "What? Why?" :laugh: Perhaps I can head myself off at the pass!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
Five or six times longer...
/// <summary>
/// Gets and sets the selected indexes
/// </summary>
/// <remarks>
/// This is necessarily complicated.
/// Remember, the data comes from a DataTable (DT) - (or a list from which the DT data
/// was derived) and the outside world expects indexes to to relative to that DT.
/// But...we display the data in a DataGridView (DGV) via a DataView (DV) and apply
/// filtering and sorting to the DV according to the user input.
/// So the selected rows we get from the DGV are in last-selected-by-user order, (which
/// if fine and dandy), but are relative to the DGV rather than the underlying DV or
/// DT data source, as the DGV is subject to the sorting and filtering applied to the DV.
///
/// So, we get the selected items from the DGV (only place we can, the DV doesn't know
/// about selection), then have to convert that to the DataRow and get the index of that
/// from the DT. But (of course) the DGV returns a DataGridViewRow object just to be
/// annoying...
/// And that's just Get!
/// </remarks>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IEnumerable<int> SelectedIndexes
{
get { return dgvData.SelectedRows.Cast<DataGridViewRow>().Select(r => _DataSource.Rows.IndexOf(((DataRowView)r.DataBoundItem).Row)); }
set { ... }
}I almost wish I'd written it longhand instead of using Linq methods... :laugh:
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
That's fine. Documentations are always longer than codes. :laugh:
Don't mind those people who say you're not HOT. At least you know you're COOL. I'm not afraid of falling, I'm afraid of the sudden stop at the end of the fall! - Richard Andrew x64
-
Fantastic! I thought I was the only one who wrote comments like that. I feel so much relief! Thanks Griff.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave KreskowiakI write comments like that too, especially if I have to do something that isn't obvious as to WHY I'm doing it. (Usually because the client is asking for something that's just the opposite of what they wanted six months ago.) It also lets other people know to think twice before changing that code willy-nilly.