datagridview

What is the usage of binding a datagridview to an arraylist full of for example some employee objects in c#?

hi I have 2 questions: 1- We all know that can create an array list full of some employee objects and bind a datagridview to it. but is that way have some advantages to other ways? 2- using the way above, how can we get the employee object info when a user clicks on a row of the datagridview? thank you ...

Delete selected row from datagridview and update DB

Hi all... I have a datagridview and the user will select a row, then click on a Delete button. The row should then delete AND the DB needs to update using tableadapters. How can I do this? The code is in C#... This is what I have so far: private void btnDelete_Click(object sender, EventArgs e) { if (this.dataGridView1.SelectedRow...

Add own columns in a binded DataGridview

Hi all, I have a DataGridView that gets a datasource assigned. I would like to create my own columns if it's (for example) DateTime. I found an example of how you can create a DateTimePicker (here) (and hopefully also a NumericUpDown) to add to the datagrid, but I don't know how i can define this column to my datagrid. Any help would b...

DataGridView get current selected object

Hi, I need to get the currently selected object from da databound DataGridView. I do not need the object of the current selected cell, but the object on which the whole row is based, in this case a BusinessObject whos properties make the columns of the grid. I could go over the DataSource, but that itself is just an object and can be ...

Row copy/paste functionality in DataGridview(windows application)

Hey Guys! I m working on C# windows application. And I have to copy the whole row of a DataGridView and paste it into a new row. How I can acchieve this? I am using framework 3.5 Can you please give me atleast idea or code would be best that how i can acieve this? Thank you! ...

Update datasource from view values (WinForms DataGridView)

I am changing DataGridView cell values programmatically, but values are not pushed to bound datasource. They are pushed only for cells belonging to selected row. How can I ask the DataGridView to push rows values into datasource? EDIT: This code seems to do the trick, but may be some better solution? grid.CurrentCell = cell; cell.Valu...

CommandText Property has not been initialized

The following code attempts to delete a selected row from a datagridview and update the database. But it's not updating the database...it's just issuing the error, "CommandText Property has not been initialized." ...any ideas? I assume it's because it's not being bound in the beginning, but at this point I'm clueless and my head is sore...

DataGridView header alignment

I am using vb.net 2005. I want one clarification for datagridview. I use the following property to set the alignment of header text: DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter This property applies to all header cells. I only want to change one headers alignment property. How ca...

Drag & Drop a Cell from column 1 row 1 to column 5 row 3 in same datagridview

I am trying to select a cell (not the entire row) and drag that cell to a different column and row in the same datagridview, i am programming in vb.net 2005 express. i have never used datagridview and dont know where to start, all the examples i have found online seem to cover everything except this behaviour. Does anyone have any ideas...

C# multi-coloured text in a single cell of a datagridview

Is it possible to change the colour of a sub string present in a datagridview cell? ...

Datagridview pagination in C# windows application

Hai guys, Can we implement default pagination like asp:gridview for a datagridview in a c# windows application? Any samples to get started? ...

Datagridview/BindingSource and sorted: add record at end of list

Hi, This will be a stupid question but I have a datagridview with a BindingSource as datasource. The bindingSources.Datasource is a own BindingList with sort support. All this works. But when a record will be inserted in the sorted list, then it will placed at the end of the datagridiview. After a refresh (example with the mouse click...

How to set up a Windowsforms databound DataGridView such that only x rows are visible?

I need to set up a windows form DataGridView, programmatically bound to a list, such that only 6 rows are visible to the user (i.e. the grid's height is only 6 cells) and a scroll bar appears when there are more than 6 elements in the bound list. All the rows need to be of the same height. Is there a configuration of properties that does...

Customized sorting on DataTable in C#?

This is a C# Winform question. I have a DataGridView which is bounded to a DataTable. I construct the DataTable myself, which several DataColumn instances. When the DataTable is bound to the DataGridView, by default, every column is sortable by clicking the headers of the DataGridView. But the sorting behavior is something "by default"....

How to custom format data in datagridview during databinding

I'm looking a way to format DataGridViewTextBoxColumn so that the value to be databinded is formatted during databind. For example I have a CompanyName property and I need to take first 5 letters from the CompanyName when databinding happens. I could hook on different DataGridView events (e.g. RowsAdded) and loop through all the rows an...

DataGridView and Cell Lock?

Using vb.net. How I lock a specific cell in the DataGridView (not a complete column)? ...

Get DataGridView checkbox cell value?

Hello guys. I'm having a strange issue here. I have a 3 column datagrid that is filled by a connection with the database. So far so good. I have an extra column, of checkbox type. I need to get it's value for perfoming a bulk operation on it. Here is the catch: When all cells are selected, it works fine. But when an user selects any...

DataGridView - How does one hook into the event associated with a cell change?

I'm using a DataGridView with C#.NET. When a user is editing a column, I need another column in the same grid to change with every keystroke/change. How/where do I insert my own code for this type of event? ...

DataGridView and the CellEndEdit Event

I have a DataGridView, and would like to hook into the CellEndEdit event. I've been able to successfully hook into the CellContentClick event, but am having issues with CellEndEdit. I added the following code to my Form1.cs file: private void dataGridView1_CellEndEdit(object sender, DataGridViewCellCancelEventArgs e) { ...

DataGridView - how to set column width?

Hello fellows, I have a WinForms application with DataGridView control. My control has five columns (say "Name", "Address", "Phone" etc) I am not happy with default column width. I want to have more control over column appearance. What I want is to be able to do one of the following: Set width of each column in percent Set width of e...