Bind ComboBox to tabel OCRG

Sander Wollaert

Hi,



I'm can't seem to find the solution to bind a new ComboBox to a SystemDataSource.

Can someone help me please?



What I have so far.





var comboBox = ComboBox.CreateNew(uniqueId);

comboBox.DataBind = DataBind.CreateNew();

comboBox.DataBind.SetBind(true, "GroupName", "OCRG");

form.AddItem(comboBox);





Kind Regards



Sander

Sebastian Schweer

Hi,



i also had the problem that i can't fill in values to a combo Box from a system table.



So i create a combobox and fill in the table about a select to the Database.



Here is my code, where i read from a User Defined Table named @BEU_ORDERREASON:



System.Data.SqlClient.SqlCommand cmdOrderReasonReader = new System.Data.SqlClient.SqlCommand();



// ComboBox will only be filled if ComboBox was empty

// So it will prevent that an error occur due to fill in double values to the ComboBox

if(ComboBox.GetFromUID(pVal.Form, "cb_ORDERRE").ValidValues.Values.Count == 0)

{

ComboBox.GetFromUID(pVal.Form, "cb_ORDERRE").ValidValues.Add("", "");



// Create SQL Command Object and fill it with and SQL Query for reading the table

cmdOrderReasonReader.CommandText = "select Code, Name from dbo.[@BEU_ORDERREASON] order by code";



// execute SQL Command

using (System.Data.SqlClient.SqlDataReader sdr_OrderReason = SwissAddonFramework.B1Connector.GetB1Connector().ExecuteQuery(cmdOrderReasonReader))

{

// Read the Data the SQL Command gives back

while(sdr_OrderReason.Read())

{

string text0 = sdr_OrderReason.GetString(0).ToString();

string text1 = sdr_OrderReason.GetString(1).ToString();



// Add the readed Data to the Combobox

ComboBox.GetFromUID(pVal.Form, "cb_ORDERRE").ValidValues.Add(text0, text1);

}

sdr_OrderReason.Close();

}

}




Best Regards,



Sebastian
0

Comments

0 comments

Please sign in to leave a comment.

Didn't find what you were looking for?

New post