我得到一个我无法弄清楚的快速问题。之前已经描述过这个问题,我查看了搜索结果,但我不知道在我的情况下我做错了什么。
这是小提取物,我希望它足够了,因为我剪切了一些自动生成的代码,使其紧凑。
错误是:
文件“............. py”,第345行,在retranslateUi中 self.loadshotlist_comp(_translate)
TypeError:loadshotlist_comp()需要1个位置参数但是2个被赋予
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
self.loadshotlist_comp(self, _translate)
def loadshotlist_comp (self, _translate):
with open(pathToShotlist) as fp:
linelist = fp.readlines()
itemcnt = 0
for line in linelist:
print(line.strip())
item = self.list_comp.item(0)
item.setText(_translate("MainWindow", line.strip()))
itemcnt += 1
fp.close()
从方法参数中删除self会导致
in retranslateUi self.loadshotlist_comp(_translate)
TypeError:loadshotlist_comp()获取1个位置参数,但是给出了2个,并且self.list_comp.item(0)在pycharm中被标记为“未解析的引用”
答案 0 :(得分:0)
调用方法时,你不应该通过MyClassList
;已经为您完成了,因为您首先通过MyClassRepository myClassRepository;
BindingSource gridBindingSource;
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
try {
myClassRepository = new MyClassRepository();
gridBindingSource = new BindingSource(myClassRepository.MyClassList, "");
dataGridView1.DataSource = gridBindingSource;
}
catch (Exception ex) {
MessageBox.Show("Error: " + ex.Message);
}
}
private void button1_Click_1(object sender, EventArgs e) {
MessageBox.Show("Binding source count:" + gridBindingSource.Count + Environment.NewLine +
"MyClassList count: " + myClassRepository.MyClassList.Count);
}
调用了该方法。
self