I have UltraGrid and i need when i click on grid row to get content from specific column of that grid. For example if I click in cell of fourth column then i need to get value of first column of the same row where i clicked.
Thanks!
I am not familiar with UltraGrid, but from what I just read at:
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.Aspx?ArticleID=1753
I believe you can simply get your value like I would from a VB.NET datagridview.
dim obj as object = UltraGrid1.Selected.Rows(0)..Cells.FromKey("Name of Cell").value
This should be a close proximity of what you need.
Related
I have a data grid view with combo box column in it, i have bind that column to datatable like this:
((grdItems.Columns[1]) as DataGridViewComboBoxColumn).DataSource = dt;
((grdItems.Columns[1]) as DataGridViewComboBoxColumn).DisplayMember = "LocationName";
((grdItems.Columns[1]) as DataGridViewComboBoxColumn).ValueMember = "Id";
now i can get the selected value like this:
var value = grdItems.Rows[0][1].Value;
but the issue is, when i manually add the rows in the gridview (without binding the grid), i cant get the value of the combobox cell.
i am adding rows like this:
grdItems.Rows.Add(1, 1, "Some Value");
when i use
var value = grdItems.Rows[0][1].Value;
this method to get the value, i returns me the text of the cell not the value i.e 1 in this case.
How can i solve this issue? since i want the value of the cell in case of adding rows manually, as well as data-bind rows.
Am assuming that by manually adding rows you mean from the UI , so one way to get the value of the newly added row is to use an event handler for the events raised when you add an row. You may use one of the following
1) RowsAdded https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowsadded(v=vs.110).aspx 2) RowPrePaint - https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowprepaint(v=vs.110).aspx - not used this much but is also an option
this.myGridView.RowsAdded += new DataGridViewRowsAddedEventHandler(myGridView_RowsAdded);
private void myGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
var newRow = this.myGridView.Rows[e.RowIndex];
}
Edit: Based on the actual requirement stated in the comments - actual requirement being retrieving the newly added row's cell value (Id) corresponding to the combox box column on button save clicked event
Assuming you have bound the combo box to a data source itself , meaning, your
combobox.DataSource=someList
so what you can do is write a linq query
someList.Where( v=>v.Text.Equals("row.Cells[1].Value")).FirstOrDefault().Id
I was working with grid-view,I try to enter some text on cell 1 on 0th row
it automatically increment other rows and I again try to write some on cell 2 on the same 0th row ,Simultaneously increments other rows.
So for I tried with
dataGridView1.AllowUserToAddRows=true;
It doesn't allow me to write inside a gridview, I think click rows has to generate automatically.
Please resolve this logic based on Cell Value Changed events.
It is not a good practice to add rows to your gridview. If you want to add something to your view, add them to the data that you are binding to it, and then bind. Very easy.
So you have something like this:
List<MyType> data = ReadDataFromSomewhere();
data.Add(new MyType(){StringItem="Something", IntItem =0});//Adding your row
data.Insert(1,new MyType(){StringItem="Other Thing", IntItem =1});//Inserting to position 1
gv.DataSource = data;
gv.DataBind();
hi everyone i'm a new coder here , i'm coding for a datagridview and have to check a row of data in the datagridview , but the problem is the datagridview must be enabled , and the selected cell will be automaticly on the first cell and the first row , if i use this code in the cells , not row , it shows an error , can someone help me to make an anti error if someone use this code when the selected item is cells and not row
if (dataGridView1.SelectedRows.Count < 0==true)
{
MessageBox.Show("Pick the data first!");
}
When i Clicked Update Which Have The Code Above
it Shows This Error
But when i Selected the Full Row and Clicked The Update Button , it Works Normally and No error
I'm not 100% sure what it is you are asking. Are you trying to make the user select full rows in your datagridview instead of individual cells? If that is the case, you'll want to set the SelectionMode property to "FullRowSelect" for your datagridview.
So my guess is that SelectionMode of your dataGridView1 is not set to FullRowSelect or RowHeaderSelect - thus you have no selected rows and dataGridView1.SelectedRows collection is always empty - that is why dataGridView1.SelectedRows[0] throws ArgumentOutOfRangeException.
Changing your dataGridView1.SelectionMode to one of the above according to desired logic should solve your problem.
I have a sample GridControl and it's dataSource = List
When I run the app, I first enter a cell value, when I click enter to move to the next cell, I lost the value of the last cell;
I mean when I tape anything in any cell I lose it when I move to anther cell!! is that normal?where is my problem?
I try to bind it to a dataset, everything go OK!!
How do I programmatically set the record pointer in a C# DataGridView?
I've tried "DataGridView.Rows[DesiredRowIndex].Selected=true;", and that does not work. All it does is highlight that row within the grid; it doesn not move the record pointer to that row.
To change the active row for the datagrid you need to set the current cell property of the datagrid to a non-hidden non-disabled, non-header cell on the row that you have selected. You'd do this like:
dataGridView1.CurrentCell = this.dataGridView1[YourColumn,YourRow];
Making sure that the cell matches the above criteria. Further information can be found at:
http://msdn.microsoft.com/en-us/library/yc4fsbf5.aspx
Try setting the focus of the DataGrid first . Some thing like this
dataGridView1.Focus();
dataGridView1.CurrentCell = this.dataGridView1[YourColumn,YourRow];
This worked in my case, hope it helps you as well