I have a datagridview which displays data from database. I have added a a textbox as a searchbox and added a text changed event. In that event I have written Search query with 'LIKE' based on text in textbox. So when I type a character it will instantly search the database and display in datagridview.
But my problem is, for large amount of data, for example a million rows, this text changed event hangs the datagridview. cant display data to datagridview fastly. Any way to speed up the process?
I would use a BackgroundWorker to search my data and handle result only if the box content didn't change in the mean time. I would also add a delay on search to avoid useless search. Actually, when needed this kind of search i prefer handle keydown on Enter or/and a button to be sure that we search when we want to.
Related
I'm working with a XamDataGrid which is bound to a DataTable. When I type in data in the rows and I hit save (to save my data back to the database), it never saves the last row entered. I'm guessing because I need to tab out of the cell that I'm currently entering data in and that it will only move the text to the DataTable upon edit end. Is there a way to copy data to the DataTable as the user enters it so they don't have to tab out to force the edit end or is there a better way? Thanks!
I would add this as comment but am unable to. Its hard to say without more information but have you tried adding UpdateSourceTrigger=PropertyChanged?
"{Binding Path=Something, UpdateSourceTrigger=PropertyChanged}"
The grid should update its source if it loses focus which may not be happening especially if your save button is in a toolbar that doesn't take focus. If that is the case, you can force the grid to end editing and commit the record by calling ExecuteCommand on the XamDataGrid and passing in the DataPresenterCommands.EndEditModeAndCommitRecord command.
I have a gridview and sqldatasource.
I want to display in a label, the number of rows from the gridview which contains a certain value in one of the columns (in the form_load event)
I thought about looping through all columns of the gridview but it will take a lot of time for this and maybe there's another way of doing this.
Can someone help me finding the "other way"?
Thanks,
Best solution would be to let the database handle filtering - you'll get much better performance that way than looping over the data on application server.
Perhaps create another SqlDataSource with an SQL statement containing appropriate WHERE condition and bind it to your label?
Hey guys. I'm having an issue with using a datagridview for a user entering data that's saved to a database. Basically, I just want them to throw stuff into a row and then my code will insert the data. I know there has to be some event for what I'm trying to and I just can't figure it out.
I tried the LeavingRow event, but the problem with that is that the final value hasn't updated when this event triggers. What I mean is, say we have a row with four columns, and the user has entered data into the first three columns. They enter info in the last column, then push down to enter a new row. The insert fails, because it thinks the last column is still empty.
I also tried UserAddsRow, but had that fail because it triggers as soon as the user starts typing to add a row, so there would be only a single character in the first column of the row I was trying to add.
Does anyone have suggestions for getting these, or some other event working for my purposes?
The two inelegant alternatives I'm weighing are a) stringing together some labels/textboxes and an add button or b) using the DataGridCell_ValueChanged event, by having some nested try/catch that will try to insert first, then if it fails try to update, and then do nothing if the update doesn't work. It's grossly inefficient, but I think it would get the job done since there's only going to be a couple dozen rows tops at one time in this datagridview.
Thank you for your time.
I typically use the RowValidated Event. I use this event because it allows for a whole row to be entered / edited before trying to save the changes.
When handling the event I get the rows that have been added, updated or deleted from the dataset (DataSet.GetChanges) and then perform the appropriate actions per type (Add, Update, Delete).
I have a gridview with empty cells. Whenever a cell is clicked I replace the contents of the cell (innerHTML property) with a string, using javascript.
I would like to save this changes on a 2d array when the index of my combobox is changed. However when I traverse the gridview during my selectedindexchanged event, none of the changes I did to the cells are visible (all the cells are empty). I guess the changes are not persistent.
How could I do this?
No, the changes are not persistent. You should do some reading about how forms on the web work--not just specific to asp.net--to get a fuller understanding. Basically, your SelectedIndexChanged event is really a POST of a form on your page. Only form values, like those in <input> or <select> fields will be sent to the server and be available to process in your C# code. So, one option would be to have a hidden input for every cell in your GridView. Another one would be to have a single hidden input which stores a string representation of a 2d array, and you would manipulate that with JavaScript every time you change the contents of a cell. Then, when you process this data in your C# code, you'll need to process the hidden inputs, not the cells of the GridView.
I want to make a single event that will capture every change in the data in a DataGridView. The list of events is pretty long. I was thinking I could bind the DataGridView to a DataTable since it has less events and it gets notified whenever the user changes the data in the DataGridView. Since the amount of data is tiny (2 columns and about 5 rows) but the user should be able to add, remove and edit rows, it would be a lot simpler if I put all possible changes in a single event so every other class that needs it gets notified when anything changes in the DataGridView's data by handing a single event. I don't want to capture when the user is typing in a cell or when a row is resized or anything that won't be normally considered as representing a change in the data. That's also why I think using a binded DataTable is a good idea. So my question is, which set of events is the minimum I need to handle in order to capture every possible change in the data contained in a DataGridView or in a DataTable (preferably a DataTable I think)?
I would try to bind to the following DataTable events:
RowDeleted
RowChanged
Those should give you what you want - notification only in case you edit, delete or add a row.