开发者

"Items collection cannot be modified when the DataSource property is set." [closed]

开发者 https://www.devze.com 2023-02-12 00:01 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Having this issue with a progra开发者_如何学JAVAm that adds files through a form to a txt file but the issue doesn't say anything about Fstream so i'm thinking it doesn't have to deal with it but i'm not sure what this problem means.

lstEmployees.Items.Add("No records found.");


Once you add a .DataSource to your listbox, you cannot modify the ListBox.Items collection. Instead, you can modify the original source.

For example, if your listbox is bound to a generic list of strings:

List<string> myList = new List<string>();
myList.Add("Item 1");
myList.Add("Item 2");
myList.Add("Item 3");

myListBox.DataSource = myList;

// need to add an item to the list after it's bound
myList.Add("No records found.");


The error message tells us that you have set the "DataSource property" on "lstEmployees". So go to "lstEmployees" properties and remove the DataSource - or if you want to keep the DataSource, don´t try to add "your own" items to "lstEmployees", as it won´t be accepted.


It looks like it's telling you that you can't do an Items.Add() to lstEmployees when you've set the DataSource on lstEmployees and called DataBind().

Without more code I can't say more.

0

精彩评论

暂无评论...
验证码 换一张
取 消