.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

Delete DataGrid row (WPF) by clicking Delete key button

Posted By:      Posted Date: October 23, 2010    Points: 0   Category :WPF
 

Hi,

I have WPF 4 desktop-based application. In one of the windows of this application I have DataGrid with data, binded with SQL Server database (via ADO.NET Entity Framework). In order to manipulate with data I have delete button, that deletes selected row from DataGrid and call SaveChanges() method.

Now I want to add support for keyboard manipulations, e.g. i want to let user to remove row by selecting and clicking on Delete keyboard button.

If I set CanUserDeleteRows="True" in window's XAML, it removes selected row, but doesn't make commit to database, in other words, it doesn't call SaveChanges() method.

I tried to add keyDown event handler to DataGrid an check if (e.Key == Key.Delete), so run remove method that removes selected row and call SaveChanges() method, but it doesn't work.

My question is how can I add keyboard event handler to DataGrid that will let remove selected row and call SaveChanges() method or just run my own method, that deals w


View Complete Post


More Related Resource Links

delete button in datagrid in MVVM not working

  
i have a datagrid. i have added a delete button as data template. but on button click, the event is not firing .  <sdk:DataGrid AutoGenerateColumns="False"                       Height="94"                       HorizontalAlignment="Left"                       Margin="0,53,0,0"                       Name="dataGrid1" VerticalAlignment="Top" Width="560"                       ItemsSource="{Binding SelectedComponentInfo.FilterComponentCriteriaMapping}"                       SelectedItem="{Binding SelectedMappingInfo, Mode=TwoWay}" CanUserReorderColumns="True" CanUserResizeColumns="True" DataContext="{Binding}">    

delete button in datagrid in MVVM not working

  
hi all, i am using VS 2010 with silverlight 4.0. i have a datagrid. i have added a delete button as data template. but on button click, the event is not firing .  <sdk:DataGrid AutoGenerateColumns="False"                       Height="94"                       HorizontalAlignment="Left"                       Margin="0,53,0,0"                       Name="dataGrid1" VerticalAlignment="Top" Width="560"                       ItemsSource="{Binding SelectedComponentInfo.FilterComponentCriteriaMapping}"                       SelectedItem="{Binding SelectedMappingInfo, Mode=TwoWay}" CanUserReorderColumns="True" CanUserResizeColumns="True" DataCon

delete button in datagrid in MVVM not working

  
hi all, i am using VS 2010 with silverlight 4.0. i have a datagrid. i have added a delete button as data template. but on button click, the event is not firing .  <sdk:DataGrid AutoGenerateColumns="False"                       Height="94"                       HorizontalAlignment="Left"                       Margin="0,53,0,0"                       Name="dataGrid1" VerticalAlignment="Top" Width="560"                       ItemsSource="{Binding SelectedComponentInfo.FilterComponentCriteriaMapping}"                       SelectedItem="{Binding SelectedMappingInfo, Mode=TwoWay}" CanUserReorderColumns="True" CanUserResizeColumns="True" DataCon

popup for delete button

  
Hi, I have a set of CheckBox where i should select and delete them. So if i click delete button without selecting any checkbox  then the popup msg should be  "Select any one checkbox" after selecting the msg should be "Are you sure you want to delete". Can anyone provide me JavaScript for this or is there any better way other than using JS. ThanksHi,I have a set of CheckBox where i should select and delete them.So if i click delete button without selecting any checkbox  then the popup msg should be "Select any one checkbox"after selecting the msg should be "Are you sure you want to delete".Can anyone provide me JavaScript for this or is there any better way other than using JS.Thanks

Gridview and delete option - Button click displays message

  
Hi, I have a gridview connected to a sql database that allows the user to delete the record. I used the ASP.net automatic "options" for this. However, I would like when the user deletes a record, a message (textbox) appears in the form to say the record has been deleted. Please can anyone provide some sample codes?   Thanks in advance. Nijojo.

delete more than one row in datagrid in silverlight 3

  
I tried to delete more than one row in datagird in silverlight, using chechbox checked, and binding to itemsource. I have following code: ---------------------- Orderlist = (System.Collections.ObjectModel.ObservableCollection<SilverlightWebService.Order>)dgOrders.ItemsSource;  System.Collections.ObjectModel.ObservableCollection<SilverlightWebService.Order> orderlist1 = new System.Collections.ObjectModel.ObservableCollection<ConcourseSilverlight.SilverlightWebService.Order>(); foreach (SilverlightWebService.Order aorder in Orderlist) { if (aorder.CheckedItem == false) orderlist1.Add(aorder); }  dgOrders.ItemsSource = orderlist1; -------------- DataGrid will be repopulated. But values selected will be defaut ones, that means data selected is not retained. may be itemsource is changes. how can I resolve this        

InfoPath Forms : Adding rows dynamically from a SQL table along with a 'Delete' button per row

  

My requirement is something like this:

In a Task Approval form, I want to have a view which shows all the rows in a particular SQL table (in a infopath repeating table?). Along with each row, there should also be a button, on clicking which the row should disappear from the infopath view table. Do you think InfoPath can handle all this? :) 

To summarize:

1. How do I add rows to a table dynamically?

2. Per row, how do I create a button dynamically?

3. How do I remove the row from the view when the button is clicked?


Listview with "delete row" button?

  

 

How would I make a ListView where each row had a button somewhere that, when clicked, would delete the row the button is on?

delete document button in ribbon gives javascript error: g is not a function

  

Hello,

We have a default SharePoint 2010 installation. So an out of the box site template, out of the box document libraries/lists etc, out of the box theme (default one) etc.

When we check the checkbox next to a document in the shared documents library, the tab in the ribbon automatically switches to the document tab. In this tab there is a button "delete document". When I click that I get a confirmation request, I click OK, and then I get a little yellow box in the upper right corner that tells me SharePoint is deleting the document, and then nothing happens.

The document stays where it is, no refresh of the page as SharePoint should do...

I have a javascript error, and in FireFox it tells me "g is not a function" on line 2 of the file inplview.js?rev=AohvE9XEf%2FI78tuaw1TGAA
Line 2 contains like 100 javascript functions on the same line, so it's impossible to find out which function or command throws the error.
This is not a file created by me, so I guess it comes with SharePoint and that I should not touch it.

So what do I do now?
I have another server that we use for SharePoint testing, and there the button works as it should, so it's not SharePoint either...
Problem is that we use this server to give basic SharePoint trainings to our employees, so it's not a very good start

Add, Modify, Delete Screen with a Datagrid on top listing all the records

  

Hi,

I have the requirement of creating an Add, Modify, Delete Screen with a Datagrid on top listing all the records. This needs to be incorporated using WPF with .Net 4.

1. I have to create a Base Control which holds a Datagrid and a tool bar with Add, Modify, Delete and Cancel buttons.
2. I have to create a Control (detail) having some fields like name, address, dateofbirth, etc. I need to inherit the above base control in this detail control to override events like btnAdd_Click, btnModify_Click, btnDelete_Click, etc.

Please let me know how to achieve this in WPF, I am facing couple of problem here:

1. I followed the approach mentioned in the below link.

http://svetoslavsavov.blogspot.com/2009/09/user-control-inheritance-in-wpf.html

Following this approach I am using a wpf custom control for my base control. But I am not sure if its good to place my Datagrid in Generic.xaml. Even with this approach I am facing problems in wiring up Datagrid Events from Generic.xaml to my custom control (my base control) class.

Please give a example solution for this problem.


How to delete a row drom database through datagrid view in Visual Basic 2008?

  

I am trying to delete a row from database through datagridview. some more information about coding is "data as Dataset" & "adap as TableAdapter" & "Group is my Table Name". I am using Visual Basic 2008 express edition with sql server 2008 Express Edition with Management Studio. I created the .mdf file in Mangement studio and i connected this file directly to the project. My opreating System is WINxp Proffessional. Now my code is given below:

For Each Row As DataGridViewRow In GroupDataGridView.SelectedRows
GroupDataGridView.Rows.Remove(Row)
'Me.adap.Update(Me.data.Group)

 

when i applied this code only one was deletd that time. But when i close the program and redubug the program whole data was deleted.

And then next i tryed this code :

Dim dr As DataRow
    dr = Me.data.Group.Rows.Item(GroupDataGridView.CurrentRow.Index)
    dr.Delete()
    Me.data.AcceptChanges()
    Me.adap.Update(Me.data.Group)

or

Me.data.Group.Rows(GroupDataGridView.CurrentRow.Index).Delete()
    Me.data.AcceptChanges()
    Me.adap.Update(Me.data)
<

Delete Datagrid Rows

  
One of the question which was asked on the silverlight forum was how to delete multiple rows of the datagrid when you have provided the checkboxs in the datagrid for the selection of more then one row in the datagrid.

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

  
In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

SqlCommand.ExecuteNonQuery() returns -1 when doing Insert / Update / Delete

  
Sometimes you end up with a return value of -1 when using the SqlClient.SqlCommand.ExecuteNonQuery method.

Why is that?



Well, the ExecuteNonQuery method is there for statements for changing data, ie. DELETE / UPDATE /INSERT, and the returned value are the number of rows affected by that statement.

When checking the documentation we can see that there are some conditions that return -1.



For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.

When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of

rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

update/delete not working on server only

  

my aspx page works in VWD, and everything works on the server EXCEPT update and delete sql functions. any ideas?

thanks 


How to use TOP in DELETE

  

Hi,

I have a large database in MSSQL 2005 (rows around 3,788,299 : size 4GB)

Two questions

1. SQL query ~ select top 100 * from [tablename], how do capture the next 100 record?

2. SQL query ~ delete top 100 from [tablename] --- MSSQL show me syntax error? How can I only delete the top 100 record?

 

thk.


delete record from excel sheet

  



Hello,

           I have write the code for deleting the data in excel sheet. but we have got the error" Deleting data in a linked table is not supported by this ISAM."

     below I paste some code snippest.

string strDelete = "Delete  from [" + strSheetName + "$]";

            cmdExcel.Connection = con;
            cmdExcel.CommandType = CommandType.Text;
            cmdExcel.CommandText = strDelete;

            cmdExcel.ExecuteNonQuery();


Please can anybody this answer.It is urgent


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend