This is how I populate my ListView:
List<Users> ListUsers = (List<Users>)FormData.Resp;
lv.Items.Clear();
foreach
(var User
in
Users)
{
ListViewDataItem ListViewDataItem =
new
ListViewDataItem();
lv.Items.Add(ListViewDataItem);
ListViewDataItem[0] = User.ID.ToString();
ListViewDataItem[1] = User.BenutzerID;
ListViewDataItem[2] = User.Nachname;
ListViewDataItem[3] = User.Vorname;
ListViewDataItem[4] = User.EMailAdresse;
}
After selecting Items, the "Text" property of CurrentItem, SelectedItem or SelectedItems[0] is always empty. I tried also to get the Text by "lv.Items[lv.SelectedIndex].Text", but where is also the text property empty. But the SelectedIndex is correct.
5 Answers, 1 is accepted
0
Sebastian
Top achievements
Rank 1
answered on 08 Oct 2018, 12:20 PM
I'm using DetailsView. So is where something special?
0
Hello, Sebastian,
When you use ListViewType.DetailsView, note that it is necessary to add columns in the RadListView.Columns collection before adding items. Additional information is available in the following help article: https://docs.telerik.com/devtools/winforms/listview/populating-with-data/unbound-mode
Here is a sample code snippet which result is illustrate din the below screenshot:
I hope this information helps.
Regards,
Dess
Progress Telerik
When you use ListViewType.DetailsView, note that it is necessary to add columns in the RadListView.Columns collection before adding items. Additional information is available in the following help article: https://docs.telerik.com/devtools/winforms/listview/populating-with-data/unbound-mode
Here is a sample code snippet which result is illustrate din the below screenshot:
public
RadForm1()
{
InitializeComponent();
this
.radListView1.ViewType = ListViewType.DetailsView;
for
(
int
i = 0; i < 5; i++)
{
this
.radListView1.Columns.Add(
"Col"
+ i);
}
List<User> ListUsers =
new
List<User>();
for
(
int
i = 0; i < 5; i++)
{
ListUsers.Add(
new
User(i,i,
"Name"
+ i,
"Last"
+ i,
"email"
+ i));
}
foreach
(var User
in
ListUsers)
{
ListViewDataItem ListViewDataItem =
new
ListViewDataItem();
this
.radListView1.Items.Add(ListViewDataItem);
ListViewDataItem[0] = User.ID.ToString();
ListViewDataItem[1] = User.BenutzerID;
ListViewDataItem[2] = User.Nachname;
ListViewDataItem[3] = User.Vorname;
ListViewDataItem[4] = User.EMailAdresse;
}
}
public
class
User
{
public
int
ID {
get
;
set
; }
public
int
BenutzerID {
get
;
set
; }
public
string
Nachname {
get
;
set
; }
public
string
Vorname {
get
;
set
; }
public
string
EMailAdresse {
get
;
set
; }
public
User(
int
iD,
int
benutzerID,
string
nachname,
string
vorname,
string
eMailAdresse)
{
this
.ID = iD;
this
.BenutzerID = benutzerID;
this
.Nachname = nachname;
this
.Vorname = vorname;
this
.EMailAdresse = eMailAdresse;
}
}
I hope this information helps.
Regards,
Dess
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
0
Hello, Sebastian,
The Text property of the ListViewDataItem depends on the applied RadListView.DisplayMember. However,when using ListViewType.DetailsView, it is appropriate to extract the desired value directly from the cell. Here is demonstrated a sample code snippet:
Regards,
Dess
Progress Telerik
The Text property of the ListViewDataItem depends on the applied RadListView.DisplayMember. However,when using ListViewType.DetailsView, it is appropriate to extract the desired value directly from the cell. Here is demonstrated a sample code snippet:
private
void
radButton1_Click(
object
sender, EventArgs e)
{
Console.WriteLine(
this
.radListView1.SelectedItem[
"Col2"
]);
}
Regards,
Dess
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Sebastian
Top achievements
Rank 1
answered on 10 Oct 2018, 01:57 PM
[...] .SelectedItem[0] [...] worked for me. Thanks :)