cancel
Showing results for 
Search instead for 
Did you mean: 

How to set date values in matrix combobox

0 Kudos
297

Hello,

I am trying to set values in a matrix combobox but I get this error: Error: 'String was not recognized as a valid DateTime.'

The values I get from the DB are as follows:

The matrix column is bound to a datatype date user datasource as below.

How do I fix this error? This is my code below:

_expDate = _form.DataSources.UserDataSources.Add("iV_15", SAPbouiCOM.BoDataType.dt_DATE, 100);
oIColumns = oIMatrix.Columns;
_colExpDate = oIColumns.Item("iV_15");
_colExpDate.DataBind.SetBound(true, "", "iV_15");
#region Item Change Event Expiry dates
_cmbExpDate = (SAPbouiCOM.ComboBox)oIMatrix.Columns.Item("iV_15").Cells.Item(pVal.Row).Specific;

int count = _cmbExpDate.ValidValues.Count;

if (count > 0)
{
_expDate.ValueEx = "";
for (int j = 0; j <= count - 1; j++)
_cmbExpDate.ValidValues.Remove(0, SAPbouiCOM.BoSearchKey.psk_Index);
}

var expDates = (from oi in _db.OITMs
join ob in _db.OBTNs
on oi.ItemCode equals ob.ItemCode
where ob.ItemCode == _itemNo.ValueEx && oi.OnHand > 0
orderby ob.ExpDate
select new
{
ExpDate = ob.ExpDate
}).Distinct().ToList();

if (expDates.Count > 0)
{
foreach (var item in expDates)
_cmbExpDate.ValidValues.Add(item.ExpDate?.ToString("yyyyMMdd"), item.ExpDate?.ToString("yyyyMMdd"));

//_cmbExpDate.Select(0, SAPbouiCOM.BoSearchKey.psk_Index);
//_expDate.ValueEx = _cmbExpDate.Value;
}
#endregion

Any help appreciated.

Kinyanjui

lenastodal
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thank you for visiting SAP Community to get answers to your questions. Since this is your first question, I recommend that you familiarize yourself with our Q&A Tutorial: https://developers.sap.com/tutorials/community-qa.html, as it provides tips for preparing questions that draw responses from our members.

Should you wish, you can revise your question by selecting Actions, then Edit.

By adding a picture to your profile you encourage readers to respond: https://www.youtube.com/watch?v=46bt1juWUUM
Many thanks!

Keep in mind, when you receive an answer that was helpful to you, accept it as best answer.

Accepted Solutions (0)

Answers (1)

Answers (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi sapinkenya,

Following code works fine for EditText:

oEdit.Value = DateTime.Now.ToString("yyyyMMdd");

Can you try the same with ComboBox in "yyyyMMdd" format and share the results with us?

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

0 Kudos

Hi Ankit,

I tried the date formatting but the combobox does not allow me to make a selection on clicking.

Edited question to show bindings.

I resolved the issue, was a problem with some bindings.