remove gridview selector column - c#

I'm sure the answer to this question is incredibly obvious, but for the life of me I can't figure out how to remove the "selector" column from the default winforms gridview. (The column the red arrow is pointing at).
I've tried programmatically removing the column gridview.Columns[0].Remove but that just removed my first data column. It doesn't show up in the "column collection" also, and I've played with all the settings that looked somewhat promising.
Thanks for the help!

Set the RowHeadersVisible to False in the GridView (it's a property)

Related

Not able to add rows in grid control repositorylookupedit goes to null on cell lost focus

I am trying to add rows in grid control using DevExpress only using repository look up edit and other columns are read only.
While I am trying to select branch name after lost focus from branch name cell, cell value come to edit null value. Please see gif image.
Please Help.
Regards
Alyasar
This problem has been solved. Just need to map Data source field and database fields.

C# Gridview: Want to create an extended gridview class that automatically hides rows with a specific value in DataKeyNames column

I'm trying to create an extended gridview class that will enable me to always have a footerrow that can be used to add data. That's the end goal.
I've tried classes that were found elsewhere on stackoverflow, but the code I found is apparently buggy (it either works when the footerrow is the only row, or it works when the footerrow is not the only row, but never both. Possibly related to the fact that I have dropdownlists in my rows). This problem was explained here: Bizarre issue with customized gridview control
The class itself is also problematic, in that the formatting is kind of messed up when the footerrow is the only row. It just doesn't look right... the color formatting is gone.
So now I'm thinking what I really want to do, is rewrite the data sources so they're based on UNION queries, so that there's always one blank row with -1 in the key column (my tables always have single incremental primary keys, so no legit row will ever have -1 in the key column), and then have a class that automatically hides any row where the value in the "DataKeyNames" field is -1.
Problem: I have no idea how to do this. :) I know how to do it in the aspx.cs code (RowDataBound event -- if(condition) {e.Row.Visible = false;}), and I know how to do it via CSS, but I don't know how to do it automatically in an extended class. I'm afraid I'm a little lost when it comes to writing extended classes.
To sum up, what I'd like to do is put an extended gridview class in my aspx code, set the usual gridview things, and have the only additional thing in my code be an added "UNION SELECT" in my datasource, and have it just automatically hide the row that the UNION SELECT provided, so that there's always at least one row in the gridview (thereby taking care of the entire footerrow not showing up problem), without me having to code anything extra in a RowDataBound event every time, because I have these gridview controls EVERYWHERE in my code.
Many thanks for any help you can provide! :)

DataGridView column aligment

I use Visual-Studio-2012. Basically I have 5 column DataGridView with product,quantity,price,+,- and I would like to align all text of products I put into my basket as MiddleCentered except actual Product description (it stays MiddleLeft as default).
I can change aligment via RowHeadersDefaultCellStyle, but I can't choose which columns I would like to align and it makes all of them MiddleCentered.
Is there any way to do so? I was trying to search on the NET, but didn't find anything clear. Help would be very appreciated.
As you have not posted your code, here is a way to aligning the text,
dataGridView1.Columns["ColumnName"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
Give a try and if you still not able to align the text, please post your code.
Holly spirit, I found the answer. I can change it via Edit Columns, selecting column and changing aligment. How stupid do I feel now. Damn...Sorry to bother guys.

How can I programmatically replicate the editmode set to EditOnKeystrokeOrF2 behavior of a datagridview?

I use Visual C# with Windows Forms.
I need to have a DatagridView Unbounded, with editmode set to EditOnKeystrokeOrF2 and AllowUsersToAddRows to True (defaults) in case the user type something.
But also I need to programmatically replicate the same behavior: "Same as when you start to type something a small icon (a pencil) appears at the left side of the row, and a new row is inserted at the end of the dgv."
Thank you for your help.
Found the solution:
Instead of adding a new row, i just tell the datagrid that the cell is dirty, and voilá: it enters in edit mode, the small pencil appears and a new uncommitted row appears under it ! :)
this.dataGridViewModificadaDetalle.NotifyCurrentCellDirty(true);

Filtering and then selecting data from flexgrid

I want to copy data from flexgrid and I have a little problem. I am using filtering and I just want to copy selected data but It´s copy data which are “hide” (not show thx to filter). For example, I used filter and in flexgrid there are just few rows and I want to all copy so click to left upper cell and it select all shown rows but when I past it somewhere it past all rows (with that which arent shown). Same when select rows with Shift button.
How can I “fix” it? I know that´s normal and it´s not error but I need to change it and I hope that there is easy way to do that. Change some property or something like that.
But if there is not I actually dont have idea how to do that “hard” way. I was thinking that maybe use _c1FlexGrid.Rows.Selected and some way control if selected row is shown. But I dont know how.
Thanks for help
Edit
I figure out that if I change SelectionMode for flexgrid from Default to ListBox then I can use Rows.Selected and it has property Visible which I can check if row is shown or not. So I can thanks to this take just rows which are shown. But now I don´t know how can I add these rows to clipboard. Before I was using this:
Clipboard.SetDataObject(_c1FlexGrid.Selection.Clip);
but now I don´t now which class use to save shown rows and then at to clipboard. And there is problem with selecting because I like SelectionMode which was default (CellRange) and selecting just all rows it is not ideal. Any ideas?
Because no one else get with better solution I´ll write here mine. As I wrote in Edit in question there were problem with SelectionMode as CellRange. I still don´t know how to "fix" it with this mode but I figure out how to do it with ListBox mode.
So in flexgrid change mode to ListBox. Then you can use this in your copy method:
foreach (C1.Win.C1FlexGrid.Row item in _c1FlexGrid.Rows.Selected)
{
if (!item.Visible)
item.Selected = false;
}
Clipboard.SetDataObject(_c1FlexGrid.Clip);
I hope that this help someone else too :)

Categories