ListView Binding event

0
0

Hi,

in VWG ListView has event ListViewItemBindingEventArgs, so we can add (remove) controls ( combobox, textbox …) to SubItems. Is it possible to do something like this in Wisej?

Thank you for your help,

Page

  • You must to post comments
0
0

When you type in the text boxes in the image attached you are causing the binding property to change, causing the data source to change causing the listview to reload the list because List<> is not BindingList<> and doesn’t keep the record index. Change it to BindingList<> and only the modified record will be updated. But:

  • Creating a textbox in each item in a ListView trying to replicate a DataGridView is a faulty approach. Use a DataGridView instead
  • The sample is using DataSourceUpdateMode.OnPropertyChanged on each TextBox data bound on each record in the ListView and attaching a KeyDown event causing the Text property to change on each keystroke causing the data source to change causing an update to the ListView and the recreation of the TextBox in your listView1_ItemBinding
  • Etc…

Use a DataGridView or a DataRepeater instead.

Attachment
  • You must to post comments
0
0

You can’t add items to a data bound listview, the same way you cannot add rows to a data bound datagridview. Data bound controls have a data source and data should be added to the data source. You don’t get an exception using AddRange() because there is a missing check in Wisej which we’ll fix in the next build. If VWG allowed adding rows or items to a data bound control it was simply wrong.

In alternative use listView.Fill(data) to create the items (or rows) from a data source and don’t keep the data binding.

  • Page Page
    Hi, it seems like the AddRange() hasn’t been fixed in the last build. What about the second question, have you taken a look at it? 2) When I change value in a textbox and move to other textbox, ListView refreshes all items. I think it should not. Thanks for your help, Page
  • You must to post comments
0
0

Hi,

I attached the sample, there are the problems I’m facing now

1)  Adding controls to SubItems

//OK

e.ListViewItem.SubItems[0].Control = tbName;
e.ListViewItem.SubItems[1].Control = tbDesc;

//EXCEPTION
e.ListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem { Control = tbName });
e.ListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem { Control = tbDesc });

//OK
e.ListViewItem.SubItems.AddRange(new ListViewItem.ListViewSubItem[] { new ListViewItem.ListViewSubItem { Control = tbName }, new ListViewItem.ListViewSubItem { Control = tbDesc } });

2) When I change value in a textbox and move to other textbox, ListView refreshes all items. I think it should not.

Thanks for your help,

Page

Attachment
  • You must to post comments
0
0

Tried this:

 this.listView1.DataSource = data;

 this.listView1.Items[0].SubItems[1].Control = new Button() { 
    Text = "Test",
    Dock = DockStyle.Fill
 };

Works without issues.

Attachment
  • You must to post comments
0
0

You can add subitems directly when the listview is data bound. The exception is correct. Add items to the data source.

if you attach a small runnable test case we may be able to help you further.

  • You must to post comments
0
0

Hi,

I followed the implementation of VWG and tried to add control to SubItems in ListViewItem, but it throws exception in Wisej. There is something wrong when Add ListViewSubItem to SubItems, please check the Wisej source.

Thanks for your help,

Page

 

 

Attachment
  • You must to post comments
0
0

Hi

You can use the listView1.Controls property to manage that

Using for example

listView1.Controls.Add(new button()) // specific control

listView1.Controls.AddRange(Control[] controls)   // array of controls

Regards

  • Page Page
    Hi, the problem that we need to bind ListView to BindingSource, number of rows is dynamic and depend on data we add the corresponding control. So your answer doesn’t work in my case. Regards, Page
  • Luca (ITG)
    We don’’t know what your case is without a runnable sample. The number of rows is always dynamic and controls are not items.
  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.