Hi,
I have a situation where after user has typed the data in the first column and pressed tab, a query will be performed and the resulting data should fill the rest of the columns.
Col 1 col2
+-----------------|+------------|---------------|--------------------|
12345 & tab Should populate rest
Thanks.
Hi Atanas,
Thanks again for your continued support. I think it makes sense to just remove the last active row. It almost seems like the row is getting added by the Ultragird as you start typing to a row and since the its bound to that data and I am gussines it automatically updates it. So, its always in sync with that. It would be great if that worked the other way round, without having to bind it each time. I could be wrong. So, to simplify, since I already know the current index (arow) im just calling the removeat before the add
_context.PurchaseAdviceListView.RemoveAt(currrow);_context.PurchaseAdviceListView.Add(loandata);
It would be nice to have a replace I suppose.
Since the problem I am having now is, if the row with the same num(id) exists, then instead of add, i need to do update.
So, its like this...
User enters the num(id) in the row[curr].col[0], the system checks if this id exists in the db. it then gets the data and populates the rest of the columns for that same row. OK
User enters another num in the next row, system checks if it exists in the current grid, if it exists then remove the row and don't allow the user to enter another of the same. OK
User updates an existing row, system still finds that the num exists (even though its the same row so its an update) it removes it. So, I guess I need to also check if its the same index or not. What is the best way to do that?
The things get more complicated, because, I have a view which is a subset of another model. Which consists of multiple of those views (grouped by batch). This whole thing is mimicking a wizard like view (with next, previous, add etc).
It would be nice, if I would just display the bigger list and simply group by batch number and when user clicks next it increases the filter and shows the next batch. so the user will feel like they are navigating through batches (shows one batch view each time).
Then I don't need this smaller view model and persisting will be easy.
I also was wondering…
Thanks again.
Hello Joy,
I can’t say for sure from the provided code why these empty rows are added to your UltraGrid. But, for the ‘Clean’ method I recommend you instead of going through the list just to delete the last active row. I assume that this row is the empty one. I modify my sample changing my data source to BindingList to be as much as closer to your scenario and I also implement the Clean and FocusCell methods.
I am sending you the modified sample, and you could run and evaluate it, please see attached zip.
If the sample doesn’t help you to fix the issue please modify it to reproduce your issue, so I will be able to investigate this on my side.
I am waiting for your feedback.
I forgot to add the following:
and what editCell does is it puts the focus on the 3rd col for the active row. I realized later that I don't need to focus to the new row rather need to focus to the 3rd col of the same row.
private void FocusCell(int row, int col)
{
this.grid.ActiveCell = grid.Rows[row].Cells[col];
this.grid.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode, false, false);
}
Thank you so very much for the sample. I implemented the followings. Since you are using DataTable and I am using BindingList and also I want to keep the behavior of the Delete function (would not like to suppress the prompt). But I have a question regarding a behavior.
In the below example. I have a function called clean. Where i go through the list and remove the ones that are null. If I don't do that, then I get the extra rows. I am assuming the empty rows that you are deleting in your code are the ones. So, the grid is somehow adding those the data source? Since I am not. I am dong only one add just for 1 row as far as I can say. So where are these getting added?
Thanks so much again.
private void grid_KeyDown(object sender, KeyEventArgs e)
var arow = this.grid.ActiveRow.Index; // saving the active row
if (e.KeyData == Keys.Tab && this.grid.ActiveCell.Column.ToString().Equals("num"))
var num = this.grid.ActiveCell.Text.Trim();
var data = _context.Services.GetSingle(num);
_context.Clean(); // need to clean the list, since it seems like it automatically adds the row. so what happens is,
// if i don't clean the list for empty data, the binding keeps adding an
// extra row each time. this probably replaces the delte you used.
_context.ListView.Add(data);
this.grid.SetDataBinding(_context.ListView, null);
this.EditCell(arow, mField);
//in _context
public void Clean()
foreach (DataView dv in this.ListView.ToList())
if (string.IsNullOrEmpty(dv.num))
this.ListView.Remove(dv);
I have managed to modify my sample. So, now once the row is filled the focus is moved to the new row. I also removed the row that contained the last id. As you have noticed in my sample a new row is added with the information that was taken from the data source/data base. The LINQ query uses the information you have provided in the first column and finds the rest of the data from the data source/data base. After that that information is added to the UltraGrid as a new row of the data source attached to the grid. Once the new row is added to the UltraGrid’s data source the added row is visualized in the grid. That’s why you need
this.gridLoanResult.SetDataBinding(_context.PurchaseAdviceListView, null);
in your project.
I hope that this will help you.
Please do not hesitate to contact me if you have any further question.