multiline column in data grid view. using c# - c#

Im using c# .net windows form application. i have a datagrid view. It has two columns.I need to make all the cells on the second column as to have multiple line. i.e a multiline column. I will edit something in a cell and press enter key. the cursor should reach the next line in the same cell. It should not go to the next cell. What should i do?

If you set the column default style like:
this.dataGridView1.Columns[index].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
you can enter multiline by pressing SHIFT-ENTER
Otherwise you could change the cell control editor overriding dataGridView or handling EditingControlShowing event (the default control is a textbox)
EDIT:
there's almost the same question here:
DataGridView: How can I make the enter key add a new line instead of changing the current cell?

Related

WinForms. How to make DataGridView to write cell value when use BindingNavigator

I have WinForms DataGridView and BindingNavigator on the From bind to the same BindingSource.
When user enter text into a cell of DataGridView (cell text editor is visible) and press "Move next" in BindingNavigator,
it is assumed that the grid close cell text editor, text should be written in the DataTable Field and record end edit.
But the grid simply ignore the entered text, and returns the old value in to the cell.
Is it possible make grid to write the entered value when navigating through BindingNavigator?
It's possible. All you need is to set the CausesValidation property of the BindingNavigator class to true.
Note that this property is false by default and also is hidden by the BindingNavigator base class ToolStrip, so you cannot do that at design time (also the documentation of the property is misleading). But you can do that via code (for instance, inside your form Load event):
this.bindingNavigator.CausesValidation = true;

Value is textbox disappears after it comes back to view

I have a datagrid, where I have styled the column headers to have a textbox in them so that I can perform filtering.
I enter some text in the textbox of the last column, then resize my window such that I will no longer see the last column. After that I resize my window again to show the last column. The value in the textbox disappears - as if the textbox control is regenerated again.
How can I retain the value?
Disabling column virtualization solved the problem for me..

How to focus cell in row for adding new record in DataGridView?

How can I programmatically focus cell in WinForms DataGridView shown highlighted on sample below?
I can easily set focus to any cell in rows 0~3 but that cell is in row 4 which looks like "virtual" because dataGridView1.Row(4) does not exist.
Not sure if i have quite got your question but does DataGridView1.NewRowIndex not work for what you want?
I tried DataGridView1.Item(0, DataGridView1.NewRowIndex).Selected = True which seems to do what I think you are trying to achieve.
The code above is on the click event of button 1 and produces the following:
If you want to 'un-select' any currently selected cell first then precede the above with If Not IsNothing(DataGridView1.CurrentCell) Then DataGridView1.CurrentCell.Selected = False, the If Not IsNothing... is to cover the code running where no cell is currently selected.
BTW I don't think you can use .CurrentCell for a cell selected on the new row, but you can use .item

DevExpress GridControl : Adding a new row "in-control" as in Windows.Forms GridView

When I try to add a new row by clicking the NewItemRow placed in bottom of the grid, it allows me to edit the cell, but when I press enter it simply doesn't add it to the list, instead takes me to the next column; Editing properties are set to True. When I run the Designer, in the Feature Browser section the Sample View allows me to add new rows as I want, but in my grid don't.
Allows me to type in the cell:
http://s28.postimg.org/3ybb5tq65/Problem.jpg
Takes me to the next column, doesn't adding what I already typed:
http://s10.postimg.org/k4cq73m5l/Problem2.jpg
Forcing me to use another Form and using code to add a new row based on text fields, what is non-convenient for the target user of my application.
In a standard DataGridView it automatically adds rows with the typed content by pressing Enter or selecting other cell.

Multiple lines in a cell in a datagrid view

I'm using C# .net.. in that I'm working with windows form application
I have a datagrid view with two columns. the first column is readonly and the other is editable. now I want every cell of the second column to support for multilines in each cell. I want to press enter key and come to the next line in the same cell. But now if I press enter key it is going to the next cell below it. I want the cursor to be in the next line of the same cell
Maybe you can:
hook to the KeyDown event
check if Enter was hit, if true:
add a linebreak to the cell's string value, and:
mark the event has handled by setting e.SuppressKeyPress to True

Categories

Resources