This is a migrated thread and some comments may be shown as answers.

Gridview can not delete or insert

3 Answers 125 Views
GridView
This is a migrated thread and some comments may be shown as answers.
he seaman
Top achievements
Rank 1
he seaman asked on 22 Jul 2010, 09:40 AM

my Gridview get datasource from webservice method,the datasource is a List collection,I add a RadContextMenu for the Gridview,like this

 <telerikGridView:RadGridView   x:Name="RadGridView1" 
                                           IsEnabled="True" RowIndicatorVisibility="Collapsed" IsReadOnly="False"
                                          
                                           IsFilteringAllowed="True"  AutoGenerateColumns="True"  CanUserFreezeColumns="False"  
                                           CanUserResizeColumns="True"  ColumnWidth="100"  >
                <telerikNavigation:RadContextMenu.ContextMenu>
                    <telerikNavigation:RadContextMenu Opened="RadContextMenu_Opened" ItemClick="RadContextMenu_ItemClick">
                        <telerikNavigation:RadContextMenu.Items>
                            <telerikNavigation:RadMenuItem Header="add" />
                            <telerikNavigation:RadMenuItem Header="edit" />
                            <telerikNavigation:RadMenuItem Header="delete" />
                        </telerikNavigation:RadContextMenu.Items>
                    </telerikNavigation:RadContextMenu>
                </telerikNavigation:RadContextMenu.ContextMenu>

            </telerikGridView:RadGridView>

private void RadContextMenu_ItemClick(object sender, RadRoutedEventArgs e)
        {
            RadContextMenu menu = (RadContextMenu)sender;
            RadMenuItem clickedItem = e.OriginalSource as RadMenuItem;
            GridViewRow row = menu.GetClickedElement<GridViewRow>();

            if (clickedItem != null && row != null)
            {
                string header = Convert.ToString(clickedItem.Header);

                switch (header)
                {
                    case "add":
                        RadGridView1.BeginInsert();
                      
                        break;
                    case "edit":
                        RadGridView1.BeginEdit();
                        break;
                    case "delete":
                        RadGridView1.Items.Remove(row.DataItem);
                        break;
                    default:
                        break;
                }
            }
        }

But the "add" and "delete" can not work,can you resolve my problem

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 22 Jul 2010, 04:47 PM
Hello he seaman,

The problem with inserting and deleting  new rows comes from the fact that the collection providing data for the grid needs to be EditableCollection or to implement the IList Interface.
In case none of this is your case, please give us more details about your project and its settings.
 

Kind regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
he seaman
Top achievements
Rank 1
answered on 23 Jul 2010, 02:05 AM
thanks admin, more detail following as


 private void Button_Click(object sender, RoutedEventArgs e)
        {
           
            DataServiceSoapClient ws = new DataServiceSoapClient();
            string startdate = this.StartDate.SelectedDate.Value.ToString("yyyydd", CultureInfo.InvariantCulture);
            string enddate = this.EndDate.SelectedDate.Value.ToString("yyyydd", CultureInfo.InvariantCulture);
            ws.operate_newAsync(((ComboBoxItem)col1.SelectedItem).Content.ToString(), ((ComboBoxItem)  col2.SelectedItem).Content.ToString(), ((ComboBoxItem)op.SelectedItem).Content.ToString(), startdate, enddate);
            ws.operate_newCompleted += new EventHandler<operate_newCompletedEventArgs>(ws_operate_newCompleted);
                
        }


  void ws_operate_newCompleted(object sender, operate_newCompletedEventArgs e)
        {
            this.RadGridView1.ItemsSource = e.Result;
        }

      [WebMethod]
        public List<Test> operate_new(string col1, string col2, string op,string ksyf,string jzyf)
        {
            string[] Parameters = new string[2];
            string[] ParametersValue = new string[2];
            int[] ParametersSize = new int[2];
            System.Data.OleDb.OleDbType[] ParametersType = new System.Data.OleDb.OleDbType[2];
            Parameters[0] = "ksyf";
            Parameters[1] = "jzyf";

            ParametersType[0] = System.Data.OleDb.OleDbType.VarChar;
            ParametersType[1] = System.Data.OleDb.OleDbType.VarChar;
            ParametersValue[0] = ksyf;
            ParametersValue[1] = jzyf;
            ParametersSize[0] = 6;
            ParametersSize[1] = 6;
            CommonInterface pComm = CommonFactory.CreateInstance(CommonData.apc);
            string sql = "{call YQ_DXCX.get_xgmdb(?,?,{resultset 0, cur1})}";
            dt = pComm.ExecuteSPforDtl(sql, Parameters, ParametersValue, ParametersType, ParametersSize); pComm.Close();
            dt.Columns.Add("RS", typeof(decimal));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                decimal d1 = Convert.ToDecimal(dt.Rows[i][col1].ToString().Trim());
                decimal d2 = Convert.ToDecimal(dt.Rows[i][col2].ToString().Trim());
                switch (op)
                {
                    case "+":
                        {
                            dt.Rows[i]["RS"] = d1 + d2;

                        } break;
                    case "-":
                        {
                            dt.Rows[i]["RS"] = d1 - d2;

                        } break;
                    case "*":
                        {
                            dt.Rows[i]["RS"] = d1 * d2;

                        } break;

                    case "/":
                        {
                            dt.Rows[i]["RS"] =d1 / d2;

                        } break;
                }
               
            }
            List<Test> RS = CommonFunction.ModelConvertHelper<Test>.ConvertToModel(dt);
            return RS;

        }

 public class Test
    {
        public string Bz { get; set; }
        public decimal Bz01 { get; set; }
        public decimal Bz02 { get; set; }
        public decimal Bz03 { get; set; }
        public decimal Bz04 { get; set; }
        public decimal Bz05 { get; set; }
        public decimal Bz06 { get; set; }
        public decimal Bz07 { get; set; }
        public decimal Bz08 { get; set; }
        public decimal Bz09 { get; set; }
        public Nullable<decimal> Bz10 { get; set; }
        public decimal? Bz11 { get; set; }
        public decimal? Bz12 { get; set; }
        public decimal? Bz13 { get; set; }
        public string Gsybz { get; set; }
        public decimal? Nsrdzdah { get; set; }
        public string Nsrsbh { get; set; }
        public string Nsrmc { get; set; }
        public string DjzclxDm { get; set; }
        public string NsrztDm { get; set; }
        public Nullable<DateTime> Hzdjrq { get; set; }
        public string NsrSwjgDm { get; set; }
        public string ZgswryDm { get; set; }
        public string ZrqDm { get; set; }
        public decimal? Dkje { get; set; }
        public decimal? Wtdz { get; set; }
        public decimal? Defpje { get; set; }
        public Nullable<DateTime> Defprq { get; set; }
        public decimal? Zsxx1 { get; set; }
        public decimal? Zsxx2 { get; set; }
        public decimal? Ttxx { get; set; }
        public decimal? Xse { get; set; }
        public decimal? Hdxse { get; set; }
        public decimal? Zsl { get; set; }
        public decimal? Bqynse { get; set; }
        public decimal? Hdynse { get; set; }
        public decimal? Jmse { get; set; }
        public decimal? Yjnse { get; set; }
        public decimal? Qzyjse { get; set; }
        public decimal? Qzdjse { get; set; }
        public decimal? Yzse { get; set; }
        public decimal? Ybtse1 { get; set; }
        public decimal? HwlwXse { get; set; }
        public decimal? HwlwDk { get; set; }
        public decimal? HwlwSk { get; set; }
        public decimal? GdzcXse { get; set; }
        public decimal? GdzcSk { get; set; }
        public decimal? MsXse { get; set; }
        public decimal? MsSk { get; set; }
        public decimal? CkmsXse { get; set; }
        public decimal? CkmsSk { get; set; }
        public decimal? Ynse { get; set; }
        public decimal? Ynsejze { get; set; }
        public decimal? Ynsehj { get; set; }
        public decimal? Yjse { get; set; }
        public decimal? Ybtse2 { get; set; }
        public decimal? RS { get; set; }
      
    }

Do you think these are enough? MY silverlight tools version is 3.

0
Maya
Telerik team
answered on 23 Jul 2010, 04:57 PM
Hello he seaman,

I have tried to reproduce your case using your code-snippets as a reference, but everything works as expected on my side.
It would be great if you could send us a sample project illustrating the problem, so that we could provide you with a possible solution.

Greetings,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
he seaman
Top achievements
Rank 1
Answers by
Maya
Telerik team
he seaman
Top achievements
Rank 1
Share this question
or