0
我正在開發用於SAP業務的工資單加載項1.我不斷收到錯誤: "NullReferenceException was unhandled by user code :Object reference not set to an instance of an object."
當我嘗試選擇嵌入SAP矩陣列單元格中的組合框項目。C#錯誤:NullReferenceException未被用戶代碼處理
我的代碼:
public void HandleMenuEvent(ref SAPbouiCOM.MenuEvent pVal)
{
// Handle Add Menu
if (pVal.MenuUID == "1282")
{
_form.Freeze(true);
oMatrix.AddRow();
_edCode.ValueEx = string.Empty;
_cmbEDDescription = oMatrix.Columns.Item("EDDesc").Cells.Item(oMatrix.RowCount).Specific;
var earnDeductDescription = Program.Kernel.Get().GetAllEarnDeductMasters().Distinct();
if (_cmbEDDescription.ValidValues.Count > 0)
{
// Do nothing
}
else
{
foreach (var item in earnDeductDescription)
{
_cmbEDDescription.ValidValues.Add(item.U_PD_description, string.Empty);
}
}
_cmbEDDescription.Select(0, SAPbouiCOM.BoSearchKey.psk_Index);
var edDescValue = string.Empty;
edDescValue = _cmbEDDescription.Value;
var edCode = earnDeductDescription.Where(x => x.U_PD_description.Trim() == edDescValue.Trim()).Select(y => y.U_PD_code).SingleOrDefault();
for (int i = 1; i
的項目更改事件
#region ItemChanged
if (pVal.ItemChanged && pVal.ColUID == "EDDesc" && pVal.Before_Action == false)
{
var earnDeductDescription = Program.Kernel.Get().GetAllEarnDeductMasters().Distinct();
var edDescValue = string.Empty;
edDescValue = _cmbEDDescription.Selected.Value; x.U_PD_description.Trim() == edDescValue.Trim()).Select(y => y.U_PD_code).SingleOrDefault();
for (int i = 1; i
出現的錯誤。這就是我重視用戶數據源到SAP列
private void BindMatrixToUserDataSource()
{
// Get main matrix
oItem = _form.Items.Item("JournalMat");
oMatrix = oItem.Specific;
_edDescription = _form.DataSources.UserDataSources.Add("EDDesc", SAPbouiCOM.BoDataType.dt_SHORT_TEXT, 30);
oColumns = oMatrix.Columns;
_coledDescription = oColumns.Item("EDDesc");
_coledDescription.DataBind.SetBound(true, "", "EDDesc");
...some code
}
任何人都可以幫我解決這個問題嗎?
「_cmbEDDescription」爲null或_cmbEDDescription.Selected爲。通過代碼來找出哪些以及爲什麼。 –
除了你面臨的問題之外,它看起來像你不確定'ref'的意思,因爲你在第一種方法中並不真正使用它。請閱讀http://pobox.com/~skeet/csharp/parameters.html –
感謝Jon Skeet,你一如既往的樂於助人。偉大的文章。 –