Hi, I am wondering if there is a better solution to a problem I am currently facing. I am still fairly new to this technology so please don't mind me and I can't seem to find a solution online.
Currently, I have a list of transaction call transactionList in the bussiness object. Starting off, I will have something like this:
private transactionList transactionList1 = null;
Then I through some method, I retrieve the list of transaction and populate the grid. Now I will have something like this:
transactionList1 = transactionList.getTransaction(something, something, something......);
FillGrid(transactionList1);
Now here's the problem... If I want to get something from the transactionList1 and do some changes to my grid I will have to do something like this.
for(){
uGrid.DisplayLayout.Rows[i].Cells[uGrid.ActiveCell.Column.Key].Value = transactionList1.getID();
}
uGrid.DisplayLayout.Rows[i].Cells[uGrid.ActiveCell.Column.Key].Value = transactionList1.getStartDate();
uGrid.DisplayLayout.Rows[i].Cells[uGrid.ActiveCell.Column.Key].Value = transactionList1.getExpireDate();
.
.....
You get the point. So I am wondering if there is any way I can set this up so I don't have to go through all 50 columns this way. Maybe I can do something to the business object or the DataSource to make things more reusable and robust.
Hello Versus,
Looking at the code you provided it seems that you are trying to updated or synchronize the values of the data source object with the values in the grid. The question here is why you are trying to do so? As soon as you set the grid’s DataSource any changes you made to DataSource object will be populated to the grid. Keep in mind you may need to call Refresh method over the grid if it is bound to IList object. As long as grid is bound to IBindingList this should not be necessary.
Therefore, please let me know what the issue you are facing is? Why you need to update or synchronize grid with data source? Also what the type of your DataSource object is?
Looking forward to your reply.
I know what I am doing require some form of binding, but I am just not too sure how binding works. The DataSource I am working on is a list.
So here's what I am trying to do, within my business object contains a lot of decimal. However these decimal isn't the thing that is being display on the Grid. Instead a formatted string of these decimal is being displayed. So we will have something like this:
private decimal value1; <- hidden="" -----="">
private decimal value2; <- hidden="" -----="">
private decimal value3; <- hidden="" -----="">
private string value1Formatted; <- displayed="" -----="">
private string value2Formatted; <- displayed="" -----="">
private string value3Formatted; <- displayed="" -----="">
However, our company wants me to implement it in a way such that the user can change the precision of the decimal for a certain column similar to excel. So what I am thinking right now is to keep the value on the DataSource in full decimal place and compare the grid value with it and format it accordingly.
uGrid.DisplayLayout.Rows[i].Cells[uGrid.ActiveCell.Column.Key].Value = FormatValue(5, transaction.value1Formatted); // Formats value1Formatted into 5 decimal
The bolded part is exactly what I am trying to avoid. Because I want to implement on other table as well. Any suggestion to work around this problem would be nice.
Edit: Found 1 solution, doing it with Reflection right now....
I am glad to hear you have resolved your issues.
Please let us know if any additional questions on this matter arise.
No worries, manage to get the problem solved by playing around with the property and PropertyInfo.
One last question, is there any way I can "recheck" the check boxes in the filter through code? Currently, when the user increase or decrease the precision of the decimal, some of them disappear. I am guessing this is due to the number in the cell is no longer the same as the number in the filter.
Edit: Never mind, problem solved. Thanks for the help.
Hi Versus,
You can format grid’s column using the standard numeric format strings provided by Microsoft. I do not know why would you want to save that value separately into string as all you need is just the format string applied to specific column. It looks to me hard to maintain solution having one numeric and one string value simultaneously. The first disadvantage I see is that they could easily get unsynchronized to begin with. All you need to save is just the display format for each column and allow the user to change it according to their preferences.
Let me know if you need further assistance regarding this matter or have any additional questions.