ListView EditItem bug

  • Thread starter Thread starter KierenH
  • Start date Start date
K

KierenH

If you set the EditIndex of a listview to 0, and then try and get the
EditItem, it is null.

EditIndex is documented as being zero-based.

Stepping into the code you can see:

public virtual ListViewItem get_EditItem()
{
if ((this._editIndex > 0) && (this._editIndex < this.Items.Count))
{
return this.Items[this._editIndex];
}
return null;
}

ListView.Items[ 0 ] returns the correct item.

Using NetFX 3.5.
 
Hi Kieren,

As for the ListView EditIndex and EditItem, I think it is the same as
GridView. For such template databound control(support edit/update),
whenever the current edit row(EditIndex) changes, it will need to reperform
the databinding on the control so as to reflect the new editing row status.
Therefore, at the time you change the editIndex, the "EditItem" property is
not populated yet. Though you can access the Item through
ListView.Items[EditIndex], it is still the original populated readonly
version. If you do need to access the EditItem, you can attach the
"ListView.DataBound" event, at that time, the EditItem has been populated.
e.g.

-=-=-=============

protected void ListView1_DataBound(object sender, EventArgs e)
{
Response.Write("<br/>ListView1_DataBound");
Response.Write("<br>ListView+EditIndex: " + ListView1.EditIndex);
Response.Write("<br>ListView+EditItem: " + ListView1.EditItem);

if(ListView1.EditIndex >=0)
Response.Write("<br>ListView+Items[EditIndex]: " +
ListView1.Items[ListView1.EditIndex]);
}

===============

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: =?Utf-8?B?S2llcmVuSA==?= <[email protected]>
Subject: ListView EditItem bug
Date: Thu, 10 Apr 2008 18:44:00 -0700
If you set the EditIndex of a listview to 0, and then try and get the
EditItem, it is null.

EditIndex is documented as being zero-based.

Stepping into the code you can see:

public virtual ListViewItem get_EditItem()
{
if ((this._editIndex > 0) && (this._editIndex < this.Items.Count))
{
return this.Items[this._editIndex];
}
return null;
}

ListView.Items[ 0 ] returns the correct item.

Using NetFX 3.5.
 
Looking at the decompiled code, even after data binding, if the edit index is
set to 0, you will still get null?

Your sample code performs the following check:
if (ListView1.EditIndex >= 0) // Greater than or equal to 0

ListView.EditItem, decompiled:
if ((this._editIndex > 0) && (this._editIndex < this.Items.Count)) //
Greater than 0



Steven Cheng said:
Hi Kieren,

As for the ListView EditIndex and EditItem, I think it is the same as
GridView. For such template databound control(support edit/update),
whenever the current edit row(EditIndex) changes, it will need to reperform
the databinding on the control so as to reflect the new editing row status.
Therefore, at the time you change the editIndex, the "EditItem" property is
not populated yet. Though you can access the Item through
ListView.Items[EditIndex], it is still the original populated readonly
version. If you do need to access the EditItem, you can attach the
"ListView.DataBound" event, at that time, the EditItem has been populated.
e.g.

-=-=-=============

protected void ListView1_DataBound(object sender, EventArgs e)
{
Response.Write("<br/>ListView1_DataBound");
Response.Write("<br>ListView+EditIndex: " + ListView1.EditIndex);
Response.Write("<br>ListView+EditItem: " + ListView1.EditItem);

if(ListView1.EditIndex >=0)
Response.Write("<br>ListView+Items[EditIndex]: " +
ListView1.Items[ListView1.EditIndex]);
}

===============

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: =?Utf-8?B?S2llcmVuSA==?= <[email protected]>
Subject: ListView EditItem bug
Date: Thu, 10 Apr 2008 18:44:00 -0700
If you set the EditIndex of a listview to 0, and then try and get the
EditItem, it is null.

EditIndex is documented as being zero-based.

Stepping into the code you can see:

public virtual ListViewItem get_EditItem()
{
if ((this._editIndex > 0) && (this._editIndex < this.Items.Count))
{
return this.Items[this._editIndex];
}
return null;
}

ListView.Items[ 0 ] returns the correct item.

Using NetFX 3.5.
 
Thanks for your quck reply Kieren,

Yes, you're right. After double check, I did get empty value when set
EditIndex to 0 and the deassembled code did indicate that it will ignore
the 0 index.

I've checked the internal bug system and did find this record, some other
community member has raised this perviously on the connect system:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedbac
kID=329314

currently according to the interal record, this problem is planned to be
addressed in the nearest SP of the .net framework. You're also welcome to
vote it on the above public bug entry.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
From: =?Utf-8?B?S2llcmVuSA==?= <[email protected]>
References: <[email protected]>
Subject: RE: ListView EditItem bug
Date: Thu, 10 Apr 2008 22:56:01 -0700

Looking at the decompiled code, even after data binding, if the edit index is
set to 0, you will still get null?

Your sample code performs the following check:
if (ListView1.EditIndex >= 0) // Greater than or equal to 0

ListView.EditItem, decompiled:
if ((this._editIndex > 0) && (this._editIndex < this.Items.Count)) //
Greater than 0



Steven Cheng said:
Hi Kieren,

As for the ListView EditIndex and EditItem, I think it is the same as
GridView. For such template databound control(support edit/update),
whenever the current edit row(EditIndex) changes, it will need to reperform
the databinding on the control so as to reflect the new editing row status.
Therefore, at the time you change the editIndex, the "EditItem" property is
not populated yet. Though you can access the Item through
ListView.Items[EditIndex], it is still the original populated readonly
version. If you do need to access the EditItem, you can attach the
"ListView.DataBound" event, at that time, the EditItem has been populated.
e.g.

-=-=-=============

protected void ListView1_DataBound(object sender, EventArgs e)
{
Response.Write("<br/>ListView1_DataBound");
Response.Write("<br>ListView+EditIndex: " + ListView1.EditIndex);
Response.Write("<br>ListView+EditItem: " + ListView1.EditItem);

if(ListView1.EditIndex >=0)
Response.Write("<br>ListView+Items[EditIndex]: " +
ListView1.Items[ListView1.EditIndex]);
}

===============

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: =?Utf-8?B?S2llcmVuSA==?= <[email protected]>
Subject: ListView EditItem bug
Date: Thu, 10 Apr 2008 18:44:00 -0700
If you set the EditIndex of a listview to 0, and then try and get the
EditItem, it is null.

EditIndex is documented as being zero-based.

Stepping into the code you can see:

public virtual ListViewItem get_EditItem()
{
if ((this._editIndex > 0) && (this._editIndex < this.Items.Count))
{
return this.Items[this._editIndex];
}
return null;
}

ListView.Items[ 0 ] returns the correct item.

Using NetFX 3.5.
 
Back
Top