How to get clicked item

Hello dear support.
I have checked the previous similar questions, but they are now not working since the recent changes in the components.
As well the examples provides does not fit the basic requirement of getting the actual clicked item.
( or at least I am failing to understand how ). so..

If I have a data model let say CompanyDataModel, and on
<ListViewEvents TValue="CompanyDataModel" Clicked="@( o => changeCompany( o.ItemData ) )"  />

public void changeCompany( CompanyDataModel o )
{
}

The method triggers but the argument is always null.

I would like to receive the data object of the clicked item.
Please help. 

13 Replies 1 reply marked as answer

SP Sowmiya Padmanaban Syncfusion Team December 2, 2020 08:48 AM UTC

Hi Yordan,  
 
Greetings from Syncfusion support. 
 
We have checked your requirement with ListView component. You can get the clicked item details in event arguments of Clicked event of ListView component using the following depicted code sample. 
 
Please, refer the below code snippet. 
 
@using Syncfusion.Blazor.Lists 
<SfListView @ref="listview" DataSource="@DataSource" > 
    <ListViewEvents TValue="DataModel" Clicked="Click"></ListViewEvents> 
    <ListViewTemplates TValue="DataModel"> 
        <Template> 
                <span class="e-list-item-header">@((context as DataModel).Text)</span>         
        </Template> 
    </ListViewTemplates> 
    <ListViewFieldSettings TValue="DataModel" Id="Id" Text="Text"></ListViewFieldSettings> 
</SfListView> 
 
@code { 
    SfListView<DataModel> listview; 
    public string HeaderTitle = "Listview"; 
 
    List<DataModel> DataSource = new List<DataModel>() 
{ 
        new DataModel { Id = "1", Text = "1", Type = "Odd"}, 
        new DataModel { Id = "2", Text = "2", Type = "Even"}, 
        new DataModel{ Id = "3", Text = "3", Type = "Odd"}, 
        new  DataModel{ Id = "4", Text = "4", Type = "Even"}, 
    }; 
 
    public class DataModel 
    { 
        public string Id { get; set; } 
        public string Text { get; set; } 
        public string Type { get; set; } 
    } 
 
    public void Click(ClickEventArgs<DataModel> args) 
    { 
        var clicked_list = args.ItemData; 
    } 
} 
 
Please, refer the below screenshot. 
 
 
 
 
Please, refer the below sample link. 
 
 
Please refer to the below links to know more about the ListView component. 
 
 
 
 
Please let us know, if you need any further assistance. 
 
Regards,  
Sowmiya.P 



YO Yordan December 2, 2020 09:14 AM UTC

First of all - thank You for Your kind and fast support! :)
Anyway I still receiving NULL :'|




SP Sowmiya Padmanaban Syncfusion Team December 3, 2020 09:32 AM UTC

Hi Yordan,  
 
We have checked your attached screenshot. We suspect your reported problem might have arisen due to incorrect mapping of field settings to the ListView component. 
 
Could you please check that you have mapped the field settings correctly to the ListView component. 
 
Please, refer the below code snippet with proper field settings. 
 
 
@using Syncfusion.Blazor.Lists 
<SfListView @ref="listview" DataSource="@DataSource" ShowHeader="true"> 
    <ListViewEvents TValue="CompanyDataModel" Clicked="Click"></ListViewEvents> 
    <ListViewTemplates TValue="CompanyDataModel"> 
        <Template> 
                <span class="e-list-item-header">@((context as CompanyDataModel).name)</span>         
        </Template> 
    </ListViewTemplates> 
    <ListViewFieldSettings TValue="CompanyDataModel" Id="id" Text="name" GroupBy="group"></ListViewFieldSettings> 
</SfListView> 
 
@code { 
    SfListView<CompanyDataModel> listview; 
    public string HeaderTitle = "Listview"; 
 
    List<CompanyDataModel> DataSource = new List<CompanyDataModel>() 
{ 
        new CompanyDataModel { id = "1", name = "1", group = "Odd"}, 
        new CompanyDataModel { id = "2", name = "2", group = "Even"}, 
        new CompanyDataModel{ id = "3", name = "3", group = "Odd"}, 
        new  CompanyDataModel{ id = "4", name = "4", group = "Even"}, 
    }; 
 
    public class CompanyDataModel 
    { 
        public string id { get; set; } 
        public string name { get; set; } 
        public string group { get; set; } 
    } 
 
    public void Click(ClickEventArgs<CompanyDataModel> args) 
    { 
        var clicked_list = args.ItemData; 
    } 
} 
 
 
Please, refer the below sample link: 
 
 
If the issue still persist, could you please share the following details to us 
 
1.     Share the code snippet your data source of ListView component. 
 
2.     Share the Syncfusion.Blazor package version you have used in your application. 
 
3.     Are you using client or server side Blazor application. 
 
4.     If possible, replicate the issue in attached sample. 
 
This information help us to find the cause of your reported problem and to provide you the prompt solution. 
 
Please let us know, if you need any further assistance. 
 
Regards,  
Sowmiya.P 


Marked as answer

YO Yordan December 3, 2020 10:34 AM UTC

Good lords. 
Seems like a DataModel without getset; } in the fields which is used for data mapping in the components is not working.
My class was like this :
    public class CompanyDataModel
    {
        public string group;
        public string name;
        public string realName;
        public string id;

        public CompanyDataModel( JObject o )
        {
            this.id = o.Value( "id" );
            this.realName = o.Value( "realname" ); 
            this.name = o.Value( "name" );
            this.group = "Main";
        }

    }

and then i've put  getset; }
    public class CompanyDataModel
    {
        public string group { get; set; }
        public string name { get; set; }
        public string realName { get; set; }
        public string id { get; set; }

        public CompanyDataModel( JObject o )
        {
            this.id = o.Value( "id" );
            this.realName = o.Value( "realname" ); 
            this.name = o.Value( "name" );
            this.group = "Main";
        }

    }

Thank You. Now it is working.
I've never expected this to cause this much troubles.


SP Sowmiya Padmanaban Syncfusion Team December 4, 2020 06:36 AM UTC

Hi Yordon, 
  
We are happy to hear that your problem has been resolved. Please contact us, if you need any help from us. 
  
Regards,  
Sowmiya.P 



RE Remi July 15, 2021 01:50 PM UTC

It helps me.I want to add put only setter and getter on POCO objetcs.


public class FileItem

{

    public int id { get; set; } // Use get/set else ListViewEvents/Clicked returns null

    public string name { get; set; }

    public Geideon.FileInfo fileRef; // Don't use get/set else get json serialisation error

}





KR Keerthana Rajendran Syncfusion Team July 16, 2021 11:03 AM UTC

Hi Remi, 
 
We are glad to hear that the provided suggestion helped you. Please get back to us if you need any further assistance.  
 
Regards, 
Keerthana R.  



ÁN Ángel February 9, 2025 03:24 AM UTC

Hello, 

Sorry to reopen this thread but, i'm getting same issue with empty data after clicked event

I'm using .Net 9 and Sync version 28.1.33

I have verified that the properties has de get/set stuff

Many thanks for your support

Regards



LD LeoLavanya Dhanaraj Syncfusion Team February 10, 2025 12:36 PM UTC

Hi Angel,


We have checked the Clicked event issue with the Blazor ListView component in the reported version(28.1.33) and framework(.NET 9). However, we were unable to replicate the issue on our end. We tested this issue in different browsers, both during the initial rendering and after interacting with the component, and we received the correct list data details for the clicked item. For your reference, we have included the validated sample and an output screenshot.



We suggest that you check the shared sample on your end. If the issue persists, please provide the steps to replicate the issue and any relevant code snippets. This information will help us better understand your situation and provide a timely resolution.


Regards,

Leo Lavanya Dhanaraj


Attachment: ListView_88e1a196.zip


HA Harshad September 1, 2025 03:49 AM UTC

Everything was working fine.  At times, I updated components.  Since my listviews were working fine in my app, I did not have to debug those.  I happened to notice while debugging another page, that my page with ListView which was working in debug as well, stopped populating ItemData of the click event's arg.  It still works as expected if I run it without debugging while "DEBUG" mode chosen and it also works in Release mode.

I find it strange that my listview's ItemData in the Click event works fine in "Release" mode.  In "Debug" mode, if I run it without debugging, it works but while debugging, the ItemData of OnListItemClicked(ClickEventArgs<DataModel> args) which is triggered on Click, is null.  


I created a new app to share but I can't reproduce it in the new app.  Unfortunately, I don't have anything that I can share.  A new page in my app with the same code that I used for the new app, also has the same issue in my app but not in the new app.


-- update 2025-08-31

I recreated the solution and added the same projects to it.  This fixed whatever was broken.  Not a ListView problem.


Thanks

Harshad




LD LeoLavanya Dhanaraj Syncfusion Team September 2, 2025 12:49 PM UTC

Hi Harshad,


We understand you’re experiencing a problem where the ItemData in the OnListItemClicked event of your ListView is null when debugging in Debug mode, but it works correctly in Release mode or when running Debug mode without a debugger included.


After investigating similar reports, we found that this issue can sometimes occur due to project configuration or build settings, rather than a problem with the ListView component itself. In one case, recreating the solution and re-adding the projects resolved the issue, suggesting a possible corruption in the solution file or mismatched build settings.


If you are still having issues with our component, please provide a minimal reproducible sample along with additional details about your issue in the form of video footage, it will help us assist you more effectively in finding a solution. Your input will be invaluable in helping us understand your issue and provide a timely resolution.


Regards,

Leo Lavanya Dhanaraj



HA Harshad replied to LeoLavanya Dhanaraj September 3, 2025 03:34 PM UTC

Hi Dhanaraj,


Thank you for your response.  It is exactly right!  I also removed and re-added the projects and it worked.  I had updated my earlier post to this effect.


Thank you for your continued support.


Regards

Harshad



LD LeoLavanya Dhanaraj Syncfusion Team September 4, 2025 06:33 AM UTC

We are glad to know that your issue has been resolved. Please get back to us if you need any further assistance in the future.



Loader.
Up arrow icon