Custom telerik gridview for winforms doesn't bind the data - telerik

Custom control for telerik grid view in winforms
In my Windows forms control library:
for MyGrid.cs (where MyGrid.cs is a component class)
public MyGrid : Telerik.WinControls.UI.RadGridView
I build and i have MyGrid.dll & i have added that in my visual studio toolbox (also referenced that dll in my consuming winform app).
Consuming winform app:
In Form1.cs, i drag and drop that MyGrid & i write this code:
MyGrid1.DataSource=ds.Table[0]; //Dataset
The grid doesn't get bound with records, whereas when i check ds row count it has 150 records. The grid however shows me green and white color (ie. alternating row color), but doesn't bind the data.
This is the code that consuming winform uses
DataSet ds = null;
string connectionString = "Data Source=test;Initial Catalog=DBname;Integrated Security=True";
string sql = " SELECT ID,FirstName from table1 ";
SqlConnection connection = null;
connnection = new SqlConnection(connectionString);
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
ds= new System.Data.DataSet();
connection.Open();
dataadapter.Fill(ds, "Table1");
MyGrid1.DataSource = ds.Tables[0];
where MyGrid1 is the custom control that is being dragged and dropped from toolbox.
Custom control code:
this.EnableAlternatingRowColor = true;
this.TableElement.AlternatingRowColor = System.Drawing.Color.Green;
this.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.AutoGenerateColumns = true;
The telerik grid is not binding the data, however when i click on the cell, it shows me the value. Any thoughts?

Related

Exporting a hyperlink in Pivot Grid

I currently have a Pivot Grid that exports both a GridView and PivotGrid. The GridView export correctly creates hyperlinks for users. However, the PivotGrid export does not. My question is, is there a way to export the hyperlink so that it is still a hyperlink?
Below is my code for what I have in my Controller to do the export.
public ActionResult ExportPivotGrid()
{
//A fresh copy of data
Session["IPDReportsData"] = IPDReport.GetReportData(Session["AdHocDataSource"].ToString(),
SCCView.Classes.Helper.OfficeId);
var pivotGridSettings = new PivotGridSettings();
pivotGridSettings.Name = "ExportPivotGrid";
pivotGridSettings.BeforePerformDataSelect = (s, e) =>
{
MVCxPivotGrid PivotGrid = s as MVCxPivotGrid;
//Get the current layout of the Pivot Grid
string layout = (string)(Session["IPDCurrentPivGridLayout"]);
PivotGrid.LoadLayoutFromString(layout, DevExpress.Web.ASPxPivotGrid.PivotGridWebOptionsLayout.DefaultLayout);
};
XlsxExportOptionsEx xopt = new XlsxExportOptionsEx();
xopt.AllowHyperLinks = DefaultBoolean.True;
xopt.ExportHyperlinks = true;
xopt.TextExportMode = TextExportMode.Text;
xopt.ExportType = DevExpress.Export.ExportType.WYSIWYG;
return PivotGridExtension.ExportToXlsx(pivotGridSettings,
Session["IPDReportsData"], true, xopt);
}
I do have this working within the Pivot Grid for the page displayed, but only by using the FieldValueDisplayText method in the settings of the Pivot Grid. However, when I tried to apply this to my export, the export never loaded.
Any help would be appreciated.

Kendo UI MVVM - Changing Model not firing DataSource change event

I have a Grid bound to a DataSource via MVVM.
I select a row in the Grid, accordingly I use this:
var grid = e.sender;
var rowSelected = grid.dataItem(grid.select());
this.set("currentAccount", rowSelected);
Where "currentAccount" holds the currently selected row. Also, "currentAccount" is bound to a Form to be edited by user.
Now, when I do changes on the form fields, they are not being automatically reflected on Grid. I need to call grid.refresh() for the changes to show on grid. With further debugging, I noticed that the datasource defined inside the viewmodel and that is used for Grid, is not firing it's Change event!
However, when user presses a button "Add new record", the following is used to create a new empty model inside the datasource, setting this new model returned by .add() function to be the "currentAccount":
var newRow = this.get("accRegDatasource").add( this._makeAccountModel( 0 ) );
this.set("currentAccount", newRow);
var row = input_map.grid().find(" tr[data-uid='" + newRow.uid + "']");
input_map.kendoGrid().select(row);
Above, I am adding a new empty row. Once I start editing the Form fields, automatically they are being reflected on the Grid without having to call grid.refresh. Even the datasource defined in the viewmodel is firing it's change event.
Any idea why this behavior?
Thanks

Event handling for Dynamically Generated ASP .NET controls in AJAX

I am dynamiccaly generating controls which include an asp .net Table, a textbox and buttons.
I then add the table to an updatePanel.
However, nomatter what i do, the event handling code for my dynamically generated buttons is just not being called. Please help:
row = new TableRow();
table.Rows.Add(row);
cell = new TableCell();
row.Cells.Add(cell);
Button button = new Button();
button.Text = "Edit";
cell.Controls.Add(button);
button.Click += (sender, eventArgs) =>
{
this.postsStatus.Text = "EDIT";
textBox.ReadOnly = false;
};
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = button.UniqueID;
trigger.EventName = "Click";
this.PostsUpdatePanel.Triggers.Add(trigger);
this.ToolkitScriptManager.RegisterAsyncPostBackControl(button);
Sled it- just put the code for dynamically generated controls in the Page_load method

RDLC image not show by set report parameter

I am working with RDLC Report in 2010
I want to bind image from external source
ReportParameter rpara = new ReportParameter("rpt1", "D:\\Projects\\Image\\logo.jpg");
ReportViewer1.LocalReport.EnableExternalImages = true;
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rpara });
I also set all the property of rdlc design like
add parameter rpt1 in report data window
add new image in body part then set image property to external and select report parameter
everything okay but still I am not able to get image on my report viewer
Try to use this way
string imagepath = "File:///" + "C:\\image.jpg";
this.reportViewer1.LocalReport.EnableExternalImages = true;
ReportParameter[] param = new ReportParameter[1];
param[0] = new ReportParameter("Path", imagepath);
this.reportViewer1.LocalReport.SetParameters(param);
this.reportViewer1.RefreshReport();

LINQ Combobox Databinding behave weird

I'm having a WinForm on witch I've a DataGridView that display a list of sites. bellow that grid i've a TextBox and a Combobox, using DataBinding the textbox show the current value "Code" grid column and the combobox show the province. The combobox is filled with a list for province
The weird thing is this:
When I change the combobox selected province for another one, at the time when the focus leave the combobox, the original value of the of the combobox return. I can't find a way for the combobox to keep the changed value.
what am I doing wrong?
Here my the code of my workbench project;
private void Form1_Load(object sender, EventArgs e)
{
context = new GMR_DEVEntities();
lSite = from t in context.tblSites where t.Actif == true select t;
this.dataGridView1.DataSource = lSite;
this.dataGridView1.AutoGenerateColumns = true;
Guid ProvinceId = Guid.Parse("00000000-0001-0000-0008-000000000001");
IQueryable<tblDomVal> provinces = from prov in context.tblDomVals where prov.pTypeDomValID == ProvinceId select prov;
comboBox1.DataSource = provinces;
comboBox1.ValueMember = "ID";
comboBox1.DisplayMember = "DescrFr";
textBox1.DataBindings.Add(new Binding("Text", lSite, "Code"));
comboBox1.DataBindings.Add(new Binding("SelectedValue", lSite, "pProvinceID", false, DataSourceUpdateMode.OnPropertyChanged));
}
Any help would be welcome :)
Hugo
Try creating a new binding context for you combo
BindingContext oBC = new BindingContext();
comboBox1.BindingContext = oBC;
comboBox1.DataBindings.Add(new Binding("SelectedValue", lSite, "pProvinceID", false, DataSourceUpdateMode.OnPropertyChanged));
While searching for a solution, I've discover that the problem have something to do with the Datatype (All my tables IDs are GUID), I've change the Binding to bind with a varchar field instead of the guid, and thing went good. So the problem have something to do with GUID. But I'll change my approach, and work with manual bind

Resources