What is the KeyField name used for on aspxgridview - vb.net

I am using the DevExpress aspxgridview in work.
The documentation says you need to specify a key field name but I cant find a reason beyond, because we said so. Does anyone know what this is for? Do I only need one, or one for each field?

The KeyFieldName is like a primary key for the Grid row, to uniquely identify a row in the grid. Lets say, you want to delete or edit a row, and click the Delete Command Button on the browser. How does the grid know which record you meant to delete? Also, if you need to update your database based on grid actions, you would expect the primary key of the grid row, which is the KeyFieldName.
KeyFieldName can be one or more datafields in your grid datasource (if multiple datafields, separate by a semi-colan). KeyFieldName is for each grid row, not each column.

Related

Enrich the information of one field with another table field

Is it possible in acces, in a table, in edit mode, normal in grid mode, in a combo box field, to make this combo box show some values, but to select them, save others?
I need this because, in Declarado, Comprobado and Documentos tables, I want a composite text to appear between a foreign key and a field in the foreign table, and that the value that is saved when selected is obviously the value of the foreign key selected.
I explain it in pictures
As you can see in the first image, I have four tables, Expedientes, Declarado, Comprobado and Documentos.
But this I just want to appear in the drop-down, I think this forces me to use a form and program it with Vb, right?
I can upload the BD if you need it
Create a form whose Record Source is the Comprobado table (whose records you are currently editing by opening the table in Grid View).
Then, insert a Combobox on the form and set the Control Source of the combobox to the Num_Expediente field, and the Row Source to a query containing both the Num_Expediente field and Nombre_OT field, e.g.:
select t.Num_Expediente, t.Nombre_OT from Expedientes t order by t.Num_Expediente
Set the Column Count property to 2 and size the columns appropriately for your data using the Column Widths property. Set the Bound Column property to column 1, so that the Num_Expediente is populated with the correct data.

WebDriver - locate dynamic column

I am using webdriver to test our application that contain table where the user can change the order of columns in a table,and also can remove/add columns (This is beside new column added by developers).
What is the right way to find the column I need?
One way is to go over the table header to find the column I am looking for so I have the column index and than I can access the right cell.
Is there other way ?
What about put unique id/class name for every element in table ?
Thanks
You can do two things for this situation:
Get handle to table element, and then navigate accordingly to get the columns or rows. Once you have this, then you can do all operations on them like click() etc.
Other way is, see the pattern of their ids/css because, most of the table that I have deal with will be having ids like this:
grid_name_1
grid_name_2
grid_name_3
Then you can have do this way:
String baseLocator = "grid_name_" + clickedRowIndex;
driver.findElement(By.id(baseLocator)).click(); //for click operation
Lets say user wants to click on the 3rd row, then clickedRowIndex will be 3 which selects the 3rd table row.

Create DataTable child row without showing it?

I am using datatable (v1.10.2 with jquery 1.9.2) because I like the out-of-the-box features (searching/sorting etc). However, now I want the ability to:
1) use animations (sliding) when showing/hiding a row
2) have the hidden row available in the DOM to change (ie, it would exist but have a display:none).
My current code to create the table looks like the following (where formatChild() returns html for a table):
if (row.child.isShown()){
row.child.hide();
tr.removeClass('shown');
} else {
row = row.child(formatChild());
row.show();
tr.addClass('shown');
}
I am using several services to change data in the child row's table via ajax and want to be able to change that data even when the row is hidden. I know I can create a map in memory and use the information in the stored map when I show the child row, but to me it is much cleaner to change the hidden row immediately.
I was hoping I could do a row()child(), modify the row, then call row()child().show() but the row isn't created in the DOM after the row.child().
Regarding the animation, I found an answer here but it involves changing the datatables code :(
I considered just using jquery to add a row to the datatable and hide it, but I couldn't find a good way to "attach" it to the primary row for sorting.
The plan I am currently leaning towards is to add a div to my primary table row that I will show/hide/update rather than using child rows at all.
What is the best practice for managing these hidden areas in a datatable (and showing them with animation)? ty
In case anyone else has the same question, I ended up using a DIV in the row rather than using DataTables' child row. When I add a new row to the datatable, the div is hidden then I hide and show (slideup/slidedown) on a click event. This gives me the nice animations, keeps the sorting simple, and let's me change information in the hidden row. Interestingly, the DIV contains a table and the text that is in that table when I create the new row is searchable; however, the text in the table that my ajax call adds/modifies is not searchable. I'm looking into how I want that to work (and may keep the div out of the search altogether if possible).

VB.NET Winforms DataGridView Select new row on Sorted DataGridView

Alright I have a DataGridView, where the user can click on the column headers to sort. When they add a new row while a sort is applied, the record isn't created until the moment they validate the row(which they cannot do till they exit the newRow). How can I make the row be selected once it is sorted?
The DataGridView is databound.
The selection mode for the grid is full row.
I'm using VB.NET with SQLite database backend.
I suspect I need to use the RowsAdded event, or DataBindingComplete events. The records in question do have a unique GUID attached but it is NOT visible in the DataGridView.
This c# question seems sort of along the lines of what I want: Select newly added Row - DataGridView and BindingSource. However the question is how do I make it fire the row validate (and thus the binding to DB) without leaving the row.
Store the primary key (id) of the added record into a new field(insert command returns that), and loop through the gridview rows and select the row with the primary key. :)

binding textboxes to a table

I have two tables that are related to each other in a 1-1 relationship (each row in the main table has exactly one corresponding row in the second table).
I also have a winform in which I'd like to show the main table in a datagridview, and for each row selected in the grid to show the fields of the corresponding row of the second table in various textboxes below the grid.
I know how to bind a datagridview to a datatable. But I'm not sure about binding several textboxes to a single row in the related datatable. I don't know what is the best way to implement it.
I'm writing in VB.Net (but can read some code in C#), using VS2008.
Any help, hints or ideas will be welcomed. Thanks.
Best way to do it is that instead of using two tables, use a join and get result in a single table, bind that table to gridview, and hide columns which you don't want to display to user.
And then use cell click event of gridview and then get the index of selected row and then use
txtBoxName.Text = GridViewName["col_name",e.RowIndex].Value.ToString();