//filter data for grid private List <ViewTable> FilterDataIntoGrid(int code) { //get all data of the 'CopyrightKind' GenreTypeList = _connector.GetList <GenreType>(urlDataGrid); //stop perform if data is not exist if (GenreTypeList == null) { return(new List <ViewTable>()); } //filter data by parameter 'code' if (GenreTypeList.Count == 0) { GenreTypeList = GenreTypeList.Where(item => item.CategoryCode == code).ToList(); } List <ViewTable> filteredData = new List <ViewTable>(); //initialize data for grid foreach (var item in GenreTypeList) { filteredData.Add(new ViewTable { Code = item.CodeI.ToString(), NameUk = item.GenreTypeTr?.SingleOrDefault(i => i?.Lang == Langs[0])?.Name ?? item.Name, NameRu = item.GenreTypeTr?.SingleOrDefault(i => i?.Lang == Langs[1])?.Name, NameEn = item.GenreTypeTr?.SingleOrDefault(i => i?.Lang == Langs[2])?.Name, VariantObject = ddlFilterGenreType.SelectedItem.Text, }); } return(filteredData); }
//show data for bottom panel private void gvCopyrightKindList_CellClick(object sender, GridViewCellEventArgs e) { if (!(gridGenreTypeList.CurrentRow.DataBoundItem is ViewTable currentRow)) { return; } if (!int.TryParse(currentRow.Code, out int code)) { return; } indexSelectedElem = GenreTypeList.FindIndex(el => el.CodeI == code); DataUpdateForBottomPanel(code); }
//action 'Save' object to grid private void btnSave_Click(object sender, EventArgs e) { //refresh bottom panel int codeIAfter = 0; if (btnSaveGenreType.Text == "Додати") { //send created object GenreType result = CheckAfterCreate(genreTypeData); codeIAfter = result.CodeI; //update data for grid gridGenreTypeList.DataSource = HandleDataForGrid(urlDataGrid); indexSelectedElem = GenreTypeList.FindIndex(el => el.CodeI == result.CodeI); //select certain item into grid gridGenreTypeList.CurrentRow = gridGenreTypeList.Rows[indexSelectedElem]; //set default state for 'Text' of the btnSave btnSaveGenreType.Text = "Зберегти"; } else if (btnSaveGenreType.Text == "Зберегти") { //save changes GenreType result = CheckAfterUpdate(genreTypeData); codeIAfter = result.CodeI; //save last selected item indexSelectedElem = gridGenreTypeList.CurrentRow.Index; //update data for grid gridGenreTypeList.DataSource = HandleDataForGrid(urlDataGrid); //select certain item into grid gridGenreTypeList.CurrentRow = gridGenreTypeList.Rows[indexSelectedElem]; } DataUpdateForBottomPanel(codeIAfter); //stop perform if elements have 'Enabled' -> true if (ControlEnabledActiveElements) { return; } //change 'Enabled' state for elements ControlEnabledActiveElements = true; }