In my WinForms project I have a Form with a DataGridView. When the application loads, the DataGridView is filled with data. In myDataGridView, SelectionMode is set to FullFowSelect.
Question 1: When the Form loads, how can I make it so that no row is selected in the DataGridView?
Question 2: And after the initial load, how can I program a Button to highlight a specific row (for example, the 5th row) in the DataGridView?
I believe you should set CurrentCell for the DataGridView
So for your case fifth row should be
dataGridView1.CurrentCell = dataGridView1[0, 4];
datagridview.Rows[index].Selected = true;
in your case to select fifth row
datagridview.Rows[4].Selected = true;
Related
I'm working on the WPF application.
My application has a DataGrid with 4 columns which works properly.
I only want the first row to have a Button with DataGrid width for inserting new data by user's click.
First row's columns may be use Column span.
Also I read How to add button in first row of datagrid column? .
This solution Insert Button to All Rows and control with Collapsing .
Thanks in advance for any help
I have two radgridviews where a row selected on grid #1 by the user appears automatically in grid #2. The new row in grid #2 needs to be programmatically selected as there may be further processing for that new row and the row index is needed.
Both grids use a datatable for their items source.
It is possible that the user can select the same item twice from grid #1. So the selected row in grid #2 must be the most current selection from grid #1.
How do I programmatically select the new row in grid #2?
Thanks
Datagrid in wpf is a derive class of ItemsControl which has the SelectedIndex property which you can use to get the first index of selection in your grid after which you can set the second grid selectedIndex to the first's.
int selectedIndex=grid1.SelectedIndex ;
grid2.SelectedIndex =selectedIndex.
I have a datagrid from devexpress in a winform application.I populated the datagrid from code (datasource=my datatable with 2 strings columns and one of type int (receive 0 and 1 values-should be checkbox on form).
I added a datagrid and from designer I added 3 columns.The last one of type checkbox.I set
UnboundType=Integer,
UnboundExpression=my column name from datatable :
DisplayFormat = Numeric,
columnedit = checkbox,
Displaycheckedvalue = 1,
displayuncheckedvalue = 0.
When I run the application always my checkboxes are blue.If i press one checkbox appear a check but when i go to the next row the previous value is again blue.What should i do so why the application keep the checks?
Don't set the column to be unbound, it is in your datasource after all.
What you want to do is just to set Displaycheckedvalue and displayuncheckedvalue as you have done, nothing more.
You can make a class which got a property for each column of your table. The int value would be a bool and so you can use List as datasource. The Grid will automaticly add checkboxes for the bool value.
If you want to use DataTable see Stig's post but in my opinion it is more beautiful to use classes and List.
I have a silverlight DataGrid, by default on page load the all the cells of the datagrid should be Readonly. I have 2 problem , can any one help me?
1.On Click on the RowHeader the current row should be editable
2. On click of the columnHearder current column of all row should be editable
This might not solve your entire problem but it should partially address it.
This is to make a column read-only in a datagrid
DataGrid.Columns[7].IsReadOnly = true;
Obviously the property can be changed from events but the data grid does not have row/column headers event handlers. Custom controls seem the way to go without introducing any new gui elements like buttons and changing the feel of the application.
I have a DataGrid bounded to OservableCollection populated cols and rows dynamically. The DataGrid's row has couple of buttons. On each button a method is called (have implemented AddHandler while generating columns).
In the handler method, I can get which row was selected. I want to know the button of which column was selected. Based on that only I can take action and open respective windows.
How do I know which button of the row was selected ?
I get the column using :
int col = myDataGrid.CurrentCell.Column.DisplayIndex;
int row = seivesTorGrid.SelectedIndex;
Based on this I am able to code respective actions.