Bind Grid to Value of Row

I have a UD field that holds a list of data.
For example:

Aaron|01/12/2014|Subject|Comments~Randy|07/17/2018|NewSubject|MoreComments~Pickle Rick|12/01/2155|TimeTravel|I’ve figured it out!

I want to bind this information to a grid. Each row would be split by ‘~’ and each column by ‘|’.
So, in the resulting example, it would end up in a grid like:

Name Time Stamp Subject Comment
Aaron 01/12/2014 Subject Comments
Randy 07/17/2018 NewSubject MoreComments
Pickle Rick 12/01/2155 TimeTravel I’ve figured it out!

I created the layout in the initialize section and that comes up fine.

this.memoGrid = (EpiUltraGrid)csm.GetNativeControlReference("ec3c42a8-7bfc-4ade-bb0d-d316f52e63cd");
memoGrid.DisplayLayout.Bands[0].Columns.Add("MemoTimeStamp","Time Stamp");

I’m not sure how to bind as the data source, however.

Here’s what I have tried so far, but no results.

	private void memoGrid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
		DataTable memoTable = new DataTable("MemoLog");
		DataColumn memoName = new DataColumn("MemoName", typeof(string));
		DataColumn memoTimeStamp = new DataColumn("MemoTimeStamp", typeof(string));
		DataColumn memoSubject = new DataColumn("MemoSubject", typeof(string));
		DataColumn memoComment = new DataColumn("MemoComment", typeof(string));

		memoTable.Columns.AddRange(new DataColumn[] {memoName, memoTimeStamp, memoSubject, memoComment});

		System.Data.DataRow edvUD34Row = edvUD34.CurrentDataRow;
		if ((edvUD34Row != null))
			string[] memoRows = edvUD34Row["MemoAuditLog_c"].ToString().Split('~');
			foreach(var row in memoRows)
				string[] memoCols = row.Split('|');
				DataRow newRow = memoTable.NewRow();
				newRow["MemoName"] = memoCols[0];
				newRow["MemoTimeStamp"] = memoCols[1];
				newRow["MemoSubject"] = memoCols[2];
				newRow["MemoComment"] = memoCols[3];
			this.memoGrid.DataSource = memoTable;

I feel like I’m missing something on record retrieval, or something… Or am I completely off base here?

That seems like a lot of work. What about splitting it up in a BAQ and bringing it in with a BAQ dataview?

Otherwise I would make a new epiDataview and bind your data table to that.

1 Like

Thought about it, but I wasn’t sure how to split and have it create multiple rows from a single row of data.
Doing the second split between the ‘|’ into columns would be trivial, but the row thing got me.

I’m already setting the data source to the data table. Wouldn’t creating an EpiDataView and binding the data table to the view then binding the view to the grid add an unnecessary step?

Okay, I got it to bind the rows properly on button click.
Where do I put the code so that it will bind at the time I retrieve the record?

I didn’t notice that part. It’s a pain to do. You would end up with an external BAQ with a view or function. There are plenty of SQL examples of splitting into multiple rows, but none of them are nice.

What’s the purpose of grabbing the memo grid?

this.memoGrid = (EpiUltraGrid)csm.GetNativeControlReference("ec3c42a8-7bfc-4ade-bb0d-d316f52e63cd");

Are you hijacking a system grid? That will cause problem since that is already bound to something.

Here’s how to make a epiDataview.

//class level 
EpiDataView memoLogEdv;
//class level 

	   memoLogEdv = new EpiDataView();
            memoLogEdv.dataView = memoTable .DefaultView;
            if ((this.oTrans.EpiDataViews.ContainsKey("memoLogEdv") == false))
                this.oTrans.Add("MemoLogEdv", this.memoLogEdv);

Fire your code on an epidataview notification. Initialize will probably work. (You can find it in the wizards)

I think that was the missing piece. Works great now.

So, I created an EpiDataView after all, which is fine, but I’m struggling to find how to set the pub/sub as it does not clear/refresh the grid when the record changes.
All of the examples I found were for BAQDataViews which I could not translate to an EpiDataView as it did not have a SubscribeToPublisher method.

Replace this

			this.memoGrid.DataSource = memoTable;


   memoLogEdv.dataView = memoTable.DefaultView;

Then set the epiBinding on the grid to the epidataview.