Telerik for UWP RadDataGrid. Getting single cell value from row selection - vb.net

I am trying to get the value of a single cell when selecting a row or multiple rows so i can run a query to fill another grid for edit. My DataGrid is bound from a dataset returned by a sql query from wcf service. i have tried accessing grid.selecteditems and have been through the documentation on the datagrid. Any help would be appreciated. if you need any more information just ask!
Reply

i can go into the drop down and see all of my columns in "Class1" (my data model used), but im not sure how to access the specific columns value i need.
If in this case, it seems like the SelectionUnit property for the RadDataGrid is Row which is the default value. If you want to the unit to select is a cell within a grid row, and get the value, you need to set the SelectionUnit to Cell as follows:
<telerikGrid:RadDataGrid
x:Name="grid"
IncrementalLoadingMode="Explicit"
ItemsSource="{Binding}"
SelectionMode="Multiple"
SelectionUnit="Cell"
SelectionChanged="grid_SelectionChanged" />
And to define a Cell when using a selection you can use the DataGridCellInfo class, that holds all the information about it. Code behind for getting the values using DataGridCellInfo class for example:
private void grid_SelectionChanged(object sender, Telerik.UI.Xaml.Controls.Grid.DataGridSelectionChangedEventArgs e)
{
var cells = grid.SelectedItems;
foreach (DataGridCellInfo cell in cells)
{
System.Diagnostics.Debug.WriteLine(cell.Value);
}
}
More details please reference this document.

Related

Access VBA Combobox Store Value in Column

I have an MS ACCESS Combo Box and I wish to change the value of one of the columns in a particular row. I get error "object required" when I run this line:
Me.ComboName.Column(12, intUseRow) = myVar
(If I am unable to use the above syntax then you should also know that the row I am trying to change is always going to be the "current" visible row so there may be another way of solving the problem due to this fact).
Thanks!
If you have a recordset that is bound to a Table/Query, you will need to change the underlying data then requery the combobox to see changes.
If you load it manually (like in the form load event) and have the comboBox Row Source Type to "Value List" - you should be able to update it like this:
Copy all the data from the selected row into variables.
Combobox.RemoveItem (selected index)
change the required variable to the new value.
construct the semicolon separated string for the value list entry
combobox.AddItem new-string.
a bit messy, but it works correctly!

Devexpress GridView count selected rows

I have a Devexpress Data Grid with a number of rows loaded.
The following properties are set:
MultiSelectNode=CheckBoxRowSelect
MultiSelect=True
I have a function that iterates through all the Rows and checks, gridview1.IsRowSelected(x) = True.
However the problem is, that even with the checkbox selected is checked it never shows as true.
The following code returns 0
Debug.Print(GridView1.GetSelectedRows().Count)
Is there an easy way to check if the checkbox is checked?
Thanks
the following piece has been working for me in various parts of my app:
First specify the key field name which your datasource collection uses:
<dvx:ASPxGridView ID="xgvGrid" runat="server"
KeyFieldName="ID" ... >
...
</dvx:ASPxGridView>
Then access selected rows IDs by:
...
List<object> values = xgvGrid.GetSelectedFieldValues("ID");...
You can obtain the selected row's count by calling values.Count afterwards.
HTH
Upon closer examination of the code a refresh method was being called which interfered with the grid .getselectedrowsmethod.

How to get dynamic created table's total column and row using Request.Form in vb.net

I am doing my project in Vb.net using MVC 4.0
I have created dynamic table and in that textboxes in td using javascript and now i want to get that table's total row and column as well for further process in Controller function.
How I can get using above using VB.net?
I have used Request.Form but the id of the textboxes in table is created uniquely so first I want to find the total column and row so based on that I can move further and check using for loop.
It seems like if you are generating your table through javascript you should also be able to set the value of a hidden field to the value you are outputting to your totals column. If you created a hidden field with the value set you should be able to access it from the Request collection. If it is not actually in a field that gets posted back you will only be able to access the value from the client-side.
document.getElementById("myInput").value = "Value you are outputting to your "total" cell
[Solved]
I got all the controls on code behind by it's name by using FormCollection just i need to do is post back the form using form action method because with using ajax i am not getting the formcollection in code behind but directly using form action method i can get all the controls name.
These are the textbox ids by which i can get the value just need to do further process like:
For Each _formvalues As String In formcol
formcol(_formvalues)
Next
fomcol is an object of FormCollection,_formvalues is used for moving one by one name coming in formcol and to take the data inside means name just write formcol(_formvalues) that's it.

Add row number in datagridview in vb.net

I am developing Windows Application in Vb.Net. Now there is one form in which I want to print records displayed in the grid. There is a facility to sort grid by clicking on the cell header in the grid And that should be print as displayed in the grid.
So I am little bit confuse about how to maintain the row number in the grid. I can take row number from DB initially when grid fill and assign data source. But when user clicks any cell header and sort that column then the row number is changed. At that time it is very difficult for me to maintain the row number.
Can any one give me idea how to maintain row number in the grid?
Thanks in advance.
I guess you need this:
NOTE: This code is in C# so you can just convert it to VB.Net
delegate:
this.dgvUserDetails.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.dgvUserDetails_RowPostPaint);
Event:
private void dgvUserDetails_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
using (SolidBrush b = new SolidBrush(dgvUserDetails.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4);
}
}
OUTPUT
grid.Rows(e.RowIndex).HeaderCell.Value = CStr(e.RowIndex + 1)
copy code for
enter image description here

vb.net change value of a cell in a databound datagridview

I have a datagridview that has been populated from a datatable using the datasource property. I need to change the value of a cell without affecting the database. So far I could only find that I have to first change the databound item but no information about how to do that. Besides, I don't want to change the databound item.
The reason for wanting to do this is that I have a list of records with a start and end time and there is a computed field that gives the difference in seconds. I need to change the value of the computed field and change the height of the row accordingly, that is, the height of each row is proportional to the duration it represents. Changes are done from a text box which increments quickly if the "increase" button is kept down and therefore I cannot change the database with each increment. Rather I would change the value in the table frequently and update the database once the increments stops.
I have tried updating the datagridview directly using this code:
dgvTasks.Rows(SelectedRowIndex).Cells(5).Value = DateAdd(DateInterval.Minute, DateDiff(DateInterval.Minute, CDate("00:00:00"), CDate(txtDuration.Text & ":00")), dgvTasks.Rows(SelectedRowIndex).Cells(4).Value)
But receive the error:
System.Data.ReadOnlyException: Column 'Column1' is read only.
I also tried updating the datatable, and allowing the calculated column to update:
dtblTasks.Rows(SelectedRowIndex)(5) = DateAdd(DateInterval.Minute, DateDiff(DateInterval.Minute, CDate("00:00:00"), CDate(txtDuration.Text & ":00")), dtblTasks.Rows(SelectedRowIndex)(4))
dgvTasks.DataSource = dtblTasks
But the calculated value doesn't change.
I am also providing an additional calculated value (in the SQL) where I find the difference in minutes and the append a string literal to that:
( CAST ( DATEDIFF(MINUTE, Tasks.TaskStart, Tasks.TaskEnd) AS NVARCHAR(10) ) + ' mins') AS TaskDurationString
Is there a way to detach the grid from the datasource but still keep the data visible in the datagrid and manipulate it (without affecting the databound object)? Or perhaps some other approach to this problem?
Updating the calculated column in the DataTable should work - I've just tried it, and both when I edit one of the values that are part of the calculated value, and when I change the value in code, that column is recalculated and the grid UI updates.
One thing to check is that you are calculating the value correctly. You should be using the DataTable~ column [Expression` property]1. Something like this:
dt.Columns["FullName"].Expression = "FirstName + LastName";
Since it appears that you don't actually need to bind any of these values to the DataTable or persist them to the database, one possible solution is to do all of this in an unbound DataGridView calculation column.
To do that add a column using the designer, then in the cell validating event have something like this:
void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Rows[e.RowIndex].Cells["TargetColumn"].Value = dataGridView1.Rows[e.RowIndex].Cells["FirstName"].Value.ToString() + dataGridView1.Rows[e.RowIndex].Cells["LastName"].Value.ToString();
dataGridView1.Rows[e.RowIndex].Height = dataGridView1.Rows[e.RowIndex].Cells["LastName"].Value.ToString().Length + dataGridView1.Rows[e.RowIndex].Cells["FullName"].Value.ToString().Length;
}