How to clear data in DataGridView? - c#

I am new to C#. How to Clear data in DataGridView?
I have some data in datagridview and I have one drop down box at every index changed
I want datagrid view will be changed. but I did not get the solution just i Added to
previous data can any one help

if you use data source to fill the grid use:
dataGridView1.DataSource=null;
dataGridView1.DataBind();
if you fill the grid programmatically use:
dataGridView1.Rows.Clear();

If you want the DataGridView change when the Dropdownlist change so u just reuse the Code grant value to Datagridview.

Related

Using Radgridview directly for data Manipulation

So i am using RadGridView for Winforms.
Now what i want to do is to perform data manipulation in the radgridview and datasource to get updated after the row loses foucs. I don't want to use textboxes or any other control for entering data.
Something like this
And after i press the new add new row and enter data
Now this data isn't being updated in the dataSource to update i need a query that needs to executed against the datasource.
Now i haven't been able to build a query because i haven't been able to figure out how to access the data of the newly created cells so that i can build a query and pass to SQLCeDataAdapter for execution.
Any pointers will be appreciated.
Im not sure about RadGridView, but I use DataGridView, wich I guess works the same way
You need to get the datarow so u can update to the database
DataRow row = ((DataRowView)eTipoDocumentoBindingSource.Current).Row;
once you have it, you can use the DataTableAdapter method update(row) to save changes to the database
You can do that, either in the click event of a save button, or in the event of focused row changed

How to add new line of row in devexpress gridcontrol?(WinForms C#)

I want to add a new line of row when pressing a button. In datagridview it would be:
datagridview1.Rows.Add()
What is the equivalent code for that in gridcontrol? Please help me.
You cannot add a new row directly to your GridControl, since this is just a container for the views. However, if you're using a GridView inside your GridControl (or any other descendant of ColumnView), you can add a new row using AddNewRow() method.
(myGridcontrol.MainView as DevExpress.XtraGrid.Views.Grid.GridView).AddNewRow();
Link to documentation
EDIT: You can access your view in a different way, of course.
The DevExpress GridControl must always be bound to a datasource: you cannot add rows directly to the GridControl object or its child GridViews.
Instead, you must bind your GridControl to a data source (via the GridControl.DataSource property), and add/remove rows via this data source.
See the 'Binding To Data' documentation at the DevExpress site for more information on the kinds of data sources that can be used with a GridControl.
You can use AddNewRow to add new row and SetRowCellValue to insert value to that row.
yourgridViewName.AddNewRow();
yourgridViewName.SetRowCellValue(rowhandle,columnName,value);
gridViewMappedFileds.UpdateCurrentRow();
Put yourgridName.RowCount-1 for rowhandle to insert the row at last.Put gridViewMappedFileds.Columns["ColumnName"] to give your columnname.

ListView how to select the text inside a cell?

well i have worked with datagridview now i need to work with a listview i dont know how to select the value it has in one cell..
my another option is when a cell was added or deleted, all this information is on datagridview
but it doesn't have a (datasourcechanged) then how can i anyone of these?
I tried secund with this code:
DataGridView1.DataSource = lvDevices
so i could select anyone but i need when in datagrid changed its value, it passed to datagridview well my another way is
how can i select the value of one cell in a ListView?
you could try this in this listview1_doubleclick event. ...
string a = listView1.SelectedItems[0].SubItems[column index corresponding selected cell].Text.

Data populated wrongly in DataGridView

I have a DataGridView that is populated using a list.
During Runtime, the user can filter the data by entering data in a textbox. I am able to do the filtering part.
But the problem i am facing is when i change the datasource to the new datasource in the Textbox1_TextChanged event, the datagridview is populating the data with rows equal to the number of rows in my new datasource but each row is replica of the first row.
When I check the DataSource of the datagridview it has the data of the new DataSource.
So when I check the row selected in the datagridview_doubleclick event, the DataBoundItem gives me the exact object that it should give according the to new datasource.
What might have gone wrong??
Maybe I am wrong, but do you need to clear the DataGridView when binding to a new datasource.... my binding skills are lacking....
Try clearing the DataGridView, before changing the datasource like :
DataGridView.Rows.Clear();

How can I add one row to a DataGridView?

I work with a WinForms app.
I want to add one row to a DataGridView that this row must enter to database.
What event handler must I use to do this?
Is your DataGridView bound to that database? If so, you should be adding and deleting rows in that data source, not in the grid control itself. Try calling the AddNew method on the binding source.
If you're using a standalone DataGridView that isn't bound to a database, then you can call one of the many overloads of the Add method of the grid control's Rows collection.
This might help you out to add a row to the DataGridView:
http://msdn.microsoft.com/de-de/library/system.windows.forms.datagridview%28v=vs.80%29.aspx
If the DataGridView isn't bound to the database, try to bound it or write the data to the database programmatically.

Categories