Create a store from Code Behind and filter its content and bind it to Combobox Ext.Net 2.2 - filter

I am creating combobox in a component Column in a GridPanel from codebehind. There is requirement to create a store and filter its content according to some condition and bind it to the created combobox. Store is getting bind to combo but filter is not working. Please help me to get the proper solution for this. My code snippet is given below.
List<object> storeDataProductClass= new List<object>();
storeDataProductClass.Add(new { text = "Class0", value = "Class0", productIndex = 0});
storeDataProductClass.Add(new { text = "Class1", value = "Class1", productIndex = 1});
storeDataProductClass.Add(new { text = "Class2", value = "Class2", productIndex = 2});
storeDataProductClass.Add(new { text = "Class3", value = "Class3", productIndex = 3});
storeDataProductClass.Add(new { text = "Class4", value = "Class4", productIndex = 4});
Ext.Net.ComboBox cmbClass = new ComboBox();
cmbClass.ID = "cmbClass_" + i;
Model classModel = new Model();
classModel.Fields.Add(new ModelField("text", ModelFieldType.String));
classModel.Fields.Add(new ModelField("value", ModelFieldType.String));
classModel.Fields.Add(new ModelField("productIndex", ModelFieldType.Int));
Ext.Net.Store storeClass = new Ext.Net.Store();
storeClass.ID = "storeClass_" + i;
storeClass.AutoDataBind = true;
storeClass.Model.Add(classModel);
storeClass.DataSource = storeDataProductClass;
storeClass.DataBind();
storeClass.Filter("productIndex", i.ToString());
cmbClass.Store.Add(storeClass);
cmbClass.DisplayField = "text";
cmbClass.ValueField = "value";
compColumn.Component.Add(cmbClass);

Related

Validate a dynamically generated CheckBox

I'm generating an asp:CheckBox dynamically and I need to validate that it is checked with a CustomValidator().
private void AddCheckBox(HtmlGenericControl newDiv, AdditionalFields field)
{
var additionalFieldDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
additionalFieldDiv.Attributes.Add("class", "additional-field-row");
var additionalLabel = new RadLabel();
additionalLabel.Text = field.Label;
additionalLabel.ID = "AdditionalLabel" + field.ControlId;
additionalLabel.CssClass += "title ";
additionalLabel.Width = new Unit(field.LabelWidth ?? 175);
if (field.Required??false) additionalLabel.CssClass += "additional-field-required";
var additionalField = new System.Web.UI.WebControls.CheckBox();
additionalField.ID = "AdditionalField" + field.ControlId;
additionalField.CssClass += "additional-field-checkbox";
additionalField.Width = new Unit(field.Width ?? 200);
var customValidator = new CustomValidator();
customValidator.ID = "CustomValidator" + field.ControlId;
//customValidator.ClientValidationFunction = "CheckBoxValidation(AdditionalField"+ field.ControlId +")";
customValidator.ControlToValidate = "AdditionalField" + field.ControlId;
customValidator.ErrorMessage = string.IsNullOrEmpty(field.ErrorMessage) ? field.Label + " required" : field.ErrorMessage;
customValidator.CssClass += "additional-fields-validator";
customValidator.Display = ValidatorDisplay.Dynamic;
customValidator.ValidationGroup = "valGroup";
customValidator.EnableClientScript = true;
newDiv.Controls.Add(additionalFieldDiv);
additionalFieldDiv.Controls.Add(additionalLabel);
additionalFieldDiv.Controls.Add(additionalField);
if (field.Required ?? false)
{
additionalFieldDiv.Controls.Add(customValidator);
}
}
I get an error if I try to use customValidator.ControlToValidate = "AdditionalField" + field.ControlId;
Control 'AdditionalField9' referenced by the ControlToValidate property of 'CustomValidator9' cannot be validated.
I have several other controls on the page that are in the validation group "valGroup" and I like the CheckBox validated client side. If I can't use the ControlToValidate property do I need to use JavaScript, and if so how do I pass the ID of the CheckBox to validate?
<script type = "text/javascript">
function ValidateCheckBox(sender, args) {
if (document.getElementById("<%=AdditionalField9.ClientID %>").checked == true) {
args.IsValid = true;
} else {
args.IsValid = false;
}
}
</script>
Hope you can help

Bind List to GridviewComboboxcolumn in telerik radgrindview (winform)

I have a generic List like
List<return> returnlist
class return
{
public string returnid {get; set;
...
public List<string> Vouchernumbers
}
I bind the returnlist to the telerik radgridview.
How can i bind the voucherlist to the GridviewComboboxcolumn for each row ?
I have bind the voucherlist to the combobox after radgridview_complete_binding.
You need to create the grid with columns and data
You need to add the combobox column, initialize it.. Please check you need to have a dataeditor in here
Assign the string to datasource
comboColumn.DataSource = new String[] { "Test1", "Test2"};
You can bind the collections too:
Binding list BindingList<ComboBoxDataSourceObject> list = new BindingList<ComboBoxDataSourceObject>();
ComboBoxDataSourceObject object1 = new ComboBoxDataSourceObject();
object1.Id = 1;
object1.MyString = "Test 1";
list.Add(object1);
ComboBoxDataSourceObject object2 = new ComboBoxDataSourceObject();
object2.Id = 2;
object2.MyString = "Test 2";
list.Add(object2);
colboCol2.DataSource = list;
radGridView1.Columns.Add(colboCol2);
create radcombobox and set datasource and add it to rad grid
eg :
GridViewComboBoxColumn col = new GridViewComboBoxColumn();
col.DataSource = DAL.ActiveDb.GetList<SalesRep>().ToList().OrderBy(x => x.RepName).Select(x => new { Id = x.Id, x.RepName });
col.DropDownStyle = RadDropDownStyle.DropDown;
col.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
col.DisplayMember = "RepName";
col.ValueMember = "Id";
col.FieldName = "RepId";
col.HeaderText = "Rep Name";
col.Width = 200;
//var t = gridColInfo.Where(x => x.ColumnName.ToLower() == "repid").FirstOrDefault();
//if (t != null)
//{
// col.Width = t.ColumnWidth;
//}
this.radGridBillwiseOpening.Columns.Add(col);

Inserting image in PPTX using OpenXML does not work

I am trying to generate a PowerPoint file containing a image using OpenXML. Unfortunately it does not work. The image is not being displayed. I've checked the file generated with the OpenXML productivity tool and I respectively unzipped the file contents. The file itself contains the image in /ppt/media/image.png and it should be displayed in the second slide.
Here's my code:
private void InsertSlide(string chartString, int position, string title, string text = "")
{
if (m_presentation == null || title == null || m_presentation.PresentationPart == null)
return;
var slide = new Slide(new CommonSlideData(new ShapeTree()));
var nonVisualProperties =
slide.CommonSlideData.ShapeTree.AppendChild(new NonVisualGroupShapeProperties());
nonVisualProperties.NonVisualDrawingProperties = new NonVisualDrawingProperties { Id = 1, Name = "" };
nonVisualProperties.NonVisualGroupShapeDrawingProperties = new NonVisualGroupShapeDrawingProperties();
nonVisualProperties.ApplicationNonVisualDrawingProperties = new ApplicationNonVisualDrawingProperties();
slide.CommonSlideData.ShapeTree.AppendChild(new GroupShapeProperties());
var slidePart = m_presentation.PresentationPart.AddNewPart<SlidePart>();
var imagePart = slidePart.AddImagePart(ImagePartType.Png, "irgendeinscheiss");
//var imageStream = new MemoryStream(Convert.FromBase64String(chartString));
using (var imageStream = new FileStream(#"C:\Users\DA\Desktop\Charts\1_Chart2_01.png", FileMode.Open))
{
imageStream.Position = 0;
imagePart.FeedData(imageStream);
}
slide.Save(slidePart);
var slideIdList = m_presentation.PresentationPart.Presentation.SlideIdList;
uint maxSlideId = 1;
SlideId prevSlideId = null;
foreach (SlideId slideId in slideIdList.ChildElements)
{
if (slideId.Id > maxSlideId)
maxSlideId = slideId.Id;
position--;
if (position == 0)
prevSlideId = slideId;
}
maxSlideId++;
SlidePart lastSlidePart;
if (prevSlideId != null)
lastSlidePart = (SlidePart)m_presentation.PresentationPart.GetPartById(prevSlideId.RelationshipId);
else
lastSlidePart = (SlidePart)m_presentation.PresentationPart.GetPartById(((SlideId)(slideIdList.ChildElements[0])).RelationshipId);
if (lastSlidePart.SlideLayoutPart != null)
slidePart.AddPart(lastSlidePart.SlideLayoutPart);
var newSlideId = slideIdList.InsertAfter(new SlideId(), prevSlideId);
newSlideId.Id = maxSlideId;
newSlideId.RelationshipId = m_presentation.PresentationPart.GetIdOfPart(slidePart);
m_presentation.PresentationPart.Presentation.Save();
}
Am I missing something? Maybe the relationships? After looking up 232243 thousand different examples, I am still stuck at this point. Thank you!
I think you need to add the image into the slide.CommonSlideData
public Slide InsertSlide(PresentationPart presentationPart, string layoutName)
{
UInt32 slideId = 256U;
// Get the Slide Id collection of the presentation document
var slideIdList = presentationPart.Presentation.SlideIdList;
if (slideIdList == null)
{
throw new NullReferenceException("The number of slide is empty, please select a ppt with a slide at least again");
}
slideId += Convert.ToUInt32(slideIdList.Count());
// Creates an Slide instance and adds its children.
Slide slide = new Slide(new CommonSlideData(new ShapeTree()));
SlidePart slidePart = presentationPart.AddNewPart<SlidePart>();
slide.Save(slidePart);
// Get SlideMasterPart and SlideLayoutPart from the existing Presentation Part
SlideMasterPart slideMasterPart = presentationPart.SlideMasterParts.First();
SlideLayoutPart slideLayoutPart = slideMasterPart.SlideLayoutParts.SingleOrDefault
(sl => sl.SlideLayout.CommonSlideData.Name.Value.Equals(layoutName, StringComparison.OrdinalIgnoreCase));
if (slideLayoutPart == null)
{
throw new Exception("The slide layout " + layoutName + " is not found");
}
slidePart.AddPart<SlideLayoutPart>(slideLayoutPart);
slidePart.Slide.CommonSlideData = (CommonSlideData)slideMasterPart.SlideLayoutParts.SingleOrDefault(
sl => sl.SlideLayout.CommonSlideData.Name.Value.Equals(layoutName)).SlideLayout.CommonSlideData.Clone();
// Create SlideId instance and Set property
SlideId newSlideId = presentationPart.Presentation.SlideIdList.AppendChild<SlideId>(new SlideId());
newSlideId.Id = slideId;
newSlideId.RelationshipId = presentationPart.GetIdOfPart(slidePart);
return GetSlideByRelationShipId(presentationPart, newSlideId.RelationshipId);
}
/// <summary>
/// Get Slide By RelationShip ID
/// </summary>
/// <param name="presentationPart">Presentation Part</param>
/// <param name="relationshipId">Relationship ID</param>
/// <returns>Slide Object</returns>
private static Slide GetSlideByRelationShipId(PresentationPart presentationPart, StringValue relationshipId)
{
// Get Slide object by Relationship ID
SlidePart slidePart = presentationPart.GetPartById(relationshipId) as SlidePart;
if (slidePart != null)
{
return slidePart.Slide;
}
else
{
return null;
}
}
Public void InsertImageInLastSlide(Slide slide, string imagePath, string imageExt)
{
// Creates an Picture instance and adds its children.
P.Picture picture = new P.Picture();
string embedId = string.Empty;
embedId = "rId" + (slide.Elements().Count() + 915).ToString();
P.NonVisualPictureProperties nonVisualPictureProperties = new P.NonVisualPictureProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)4U, Name = "Picture 5" },
new P.NonVisualPictureDrawingProperties(new A.PictureLocks() { NoChangeAspect = true }),
new ApplicationNonVisualDrawingProperties());
P.BlipFill blipFill = new P.BlipFill();
Blip blip = new Blip() { Embed = embedId };
// Creates an BlipExtensionList instance and adds its children
BlipExtensionList blipExtensionList = new BlipExtensionList();
BlipExtension blipExtension = new BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" };
UseLocalDpi useLocalDpi = new UseLocalDpi() { Val = false };
useLocalDpi.AddNamespaceDeclaration("a14",
"http://schemas.microsoft.com/office/drawing/2010/main");
blipExtension.Append(useLocalDpi);
blipExtensionList.Append(blipExtension);
blip.Append(blipExtensionList);
Stretch stretch = new Stretch();
FillRectangle fillRectangle = new FillRectangle();
stretch.Append(fillRectangle);
blipFill.Append(blip);
blipFill.Append(stretch);
// Creates an ShapeProperties instance and adds its children.
P.ShapeProperties shapeProperties = new P.ShapeProperties();
A.Transform2D transform2D = new A.Transform2D();
A.Offset offset = new A.Offset() { X = 457200L, Y = 1524000L };
A.Extents extents = new A.Extents() { Cx = 8229600L, Cy = 5029200L };
transform2D.Append(offset);
transform2D.Append(extents);
A.PresetGeometry presetGeometry = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle };
A.AdjustValueList adjustValueList = new A.AdjustValueList();
presetGeometry.Append(adjustValueList);
shapeProperties.Append(transform2D);
shapeProperties.Append(presetGeometry);
picture.Append(nonVisualPictureProperties);
picture.Append(blipFill);
picture.Append(shapeProperties);
slide.CommonSlideData.ShapeTree.AppendChild(picture);
// Generates content of imagePart.
ImagePart imagePart = slide.SlidePart.AddNewPart<ImagePart>(imageExt, embedId);
FileStream fileStream = new FileStream(imagePath, FileMode.Open);
imagePart.FeedData(fileStream);
fileStream.Close();
}
Source Code

Border for created cell with npoi

I have an Excel File which serves as a template for my Excel work and I want to programatically fill this template with data.
When I create a row and an accompanying cell and set a border for the newly created cell, the whole sheet is assigned this border. Naturally, I only want the single cell to have that border. Here is the code:
string path = Application.StartupPath + "\\" + "Excels\\myTemplate.xls";
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
HSSFWorkbook templateWorkbook = new HSSFWorkbook(fs, true);
HSSFSheet sheet = templateWorkbook.GetSheet("sheet2");
int rowIndex = 3;
var row = sheet.CreateRow(rowIndex);
int i = 0;
string zoneNo;
string SubsidiaryCode = string.Empty;
foreach (DataRow r in dtBill.Rows)
{
SubsidiaryCode = (r["SubsidiaryCode"].ToString().Trim());
zoneNo = (r["ZoneNO"].ToString().Trim());
HSSFCell cell = (HSSFCell)row.CreateCell(i);
cell.SetCellValue("Zone " + zoneNo + "-code :" + SubsidiaryCode);
cell.CellStyle.BorderBottom = HSSFCellStyle.BORDER_MEDIUM;
i++;
row.CreateCell(i).SetCellValue(r["Date"].ToString().Trim());
row.CreateCell(i).CellStyle.BorderBottom = HSSFCellStyle.BORDER_MEDIUM;
i++;
rowIndex++;
row = sheet.CreateRow(rowIndex);
i = 0;
}
sheet.ForceFormulaRecalculation = true;
I found the answer
var row = sheet.CreateRow(rowGlobal);
HSSFCellStyle style1 = templateWorkbook.CreateCellStyle();
style1.BorderRight = HSSFCellStyle.BORDER_MEDIUM;
style1.BorderBottom = HSSFCellStyle.BORDER_MEDIUM;
style1.Alignment = HSSFCellStyle.ALIGN_CENTER;
//style1.FillPattern = HSSFCellStyle.SOLID_FOREGROUND;
//style1.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.GREEN.index;
HSSFFont font1 = templateWorkbook.CreateFont();
//font1.Color = NPOI.HSSF.Util.HSSFColor.BROWN.index;
font1.FontName = "B Nazanin";
style1.SetFont(font1);
cell = row.CreateCell(2);
cell.SetCellValue(0);
cell.CellStyle = style1;

How to add a 2-column combobox to XtraGrid

How can add a 2-column combobox to Xtragrid which has one col is stored to database and the other is used to display in the xtragrid.
Thank so much
You need to create a RepositoryItemLookUpEdit then set it as your column.ColumnEdit property:
//Set the dropdown values for the cell
RepositoryItemLookUpEdit colCombo = new RepositoryItemLookUpEdit();
colCombo.ShowHeader = true;
colCombo.ShowFooter = false;
colCombo.DataSource = dsRules.YOURTABLE;
colCombo.DisplayMember = "DESCRIPTION";
colCombo.ValueMember = "ID"; //Your DB column
colCombo.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
colCombo.NullText = "";
//colGRIDCOLUMN is your DevExpress.XtraGrid.Columns.GridColumn
colGRIDCOLUMN.ColumnEdit = colCombo;
LookUpColumnInfoCollection coll = colCombo.Columns;
coll.Add(new LookUpColumnInfo("DESCRIPTION", "DESCRIPTION", 0));
coll.Add(new LookUpColumnInfo("ID", "ID", 0));
colCombo.BestFit();

Resources