Display Image to RepositoryPictureEdit in gridView of DevExpress...? - devexpress

I am working in DevExpress Gridview Concepts. I require one User Image in my grid field. i m working in winforms platforms.
My Datatable has only path of image. I dont know how to bind an image to repositoryPictureEdit Control
Kindly provide any solution.

You could using a ImageEdit. This is a dropdown of Images. So you generate Images first via:
Image.FromFile(Path);
Add them to a List or ImageList and fill the dropdown with it. Then you just bind the index of the picture to your column.
I hope this is able to work in your case.
edit: OR
At first you have to create a UnboundColumn in your Grid. Just create a column and set the Property 'UnboundType' to object. Then set a RepositoryPictureEdit as ColumnEdit. Now you have a Column which got a pictureedit in each row. To populate the Images you can handle the CustomUnboundColumnData event. This event you can find on the GridView.
To accomplish this task do following:
Run GridView Designer -> Change to columns at the left side
Add Column
In the Propertywindow ->
set the Columnedit to repositorypictureedit
set the UnboundType to object
Activate the CustomUnboundColumnData event (you can find in the
GridView) -> this event fires on loading Grid for every cell.
With e.ListSourceRowIndex you can get the row of your datasource appending to the unboundcolumn. So you could do following:
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (e.Column.Name == "MyColumn")
{
clsTest test = myListAsDataSource[e.ListSourceRowIndex];
e.Value = test.Bild;
}
}
I hope this can help you.

Related

Telerik RadGrid maintain scroll position after row selection

I have a RadGrid that has a WebUserControl for each row of the grid to allow the user to edit that row. When I click the edit button to expand the row (this opens up a .ascx control within the grid for that row), it always scrolls to the top of the page. The user then has to scroll down to find the row they selected with the row expanded to begin editing that row.
I found in another post that adding RadGrid1.ClientSettings.AllowKeyboardNavigation = true; prior to data binding the grid helps to maintain scroll position. This kind of works and you only have to scroll down one click of the mouse wheel to find the row to edit; not good enough.
I also have set MaintainScrollPositionOnPostback=“true" on the aspx page.
I also have set on the RadGrid itself under client settings SaveScrollPosition=“true".
What I'd like to see is the page not move at all when the user clicks on edit for the given row. I would like to maintain the scroll position on the page.
Can this be accomplished? If so, how?
I finally figured out why my grid always scrolled to the top. It was my fault. I wanted the user to see any message from the WebUserControl when control pass back to the parent page. The RadGrid1.ClientSettings.Scrolling.ScrollTop = 0; was the issue.
I had the following code listed:
private void DisplayMessage()
{
// Display any messages from RadGrid2 that occurred in WebUserControl
if (!string.IsNullOrEmpty(Convert.ToString(Session["LabelUpdated"])))
{
lblUpdated.Text = Convert.ToString(Session["LabelUpdated"]);
Session["LabelUpdated"] = null;
}
RadGrid1.ClientSettings.Scrolling.ScrollTop = "0";
lblUpdated.Focus();
}
I've since changed it to what is below:
private void DisplayMessage()
{
// Display any messages from RadGrid2 that occurren in WebUserControl
if (!string.IsNullOrEmpty(Convert.ToString(Session["LabelUpdated"])))
{
lblUpdated.Text = Convert.ToString(Session["LabelUpdated"]);
Session["LabelUpdated"] = null;
RadGrid1.ClientSettings.Scrolling.ScrollTop = "0";
lblUpdated.Focus();
}
}
After the change the grid will only scroll to the top when a message is present from the WebUserControl.

Add new row when previous "new row" is saved in Kendo Grid

I have created a kendo.data.dataSource without transport (only data with model and fields) with success, and I am able to bind it to the KendoUI Grid on my page.
After loading, the grid is empty. I do calling the net line to add a empty data item in the grid so the user can enter data directly in the grid (inline mode).
$("#divid").data("kendoGrid").addRow();
This all works.
But after the user finished the input and hit the OK/Save button, I like to add a new empty row immediatly, below the previous added row. I try this during the grid function Save:
save: function(e) {
$("#divid").data("kendoGrid").addRow();
}
But the previous row with inserted data disappear and a new empty dataitem isn't added.
Also trying this same way during the datasource event 'change', but with the same behaviour.
My question is, what I doing wrong or what is the best way to add a new empty row to the Kendo Grid when user hits the OK/save button of a current inine editing row.
If you want to save multiple record at a time, you can go for batch editing. You can bind a keypress event to create new row as well. Try this:
$(document.body).keypress(function (e) {
if (e.keyCode == 13) {
var grid = $("#grid").data("kendoGrid");
grid.addRow();
}
});
13 is the value for enter key.

Devexpress ASPxGridView New Row Disabled

I have code like this with devexpress ASPxGridView. Everything goes well, but when I try to add new row, new row's textbox is disabled...
I have KeyFieldName set.
void BindGrid()
{
var AnnObj = SearchBarBanners.Select(i => new
{
Caption = i.Attribute("caption").Value,
ID = i.Attribute("id").Value, // this is generated by Guid
}).ToList();
ImagesGrid.DataSource = AnnObj;
ImagesGrid.DataBind();
}
I can suggest you two things without grid markup:
1. Call BindGrid method in Page_Init
2. If your datasource initially returns zero rows, grid won't be able to determine type of objects that will be rendered in grid. You need to use ASPxGridView.ForceDataRowType in order to solve this problem.
Use recommendations from the Q392961 DX Article to resolve this issue.

How to make the datagrid with no data?

I have a page with two buttons: one is Load Data and the other Clear Data.
I am using DataSet and have used ds.Tables.Clear() in that click code.
If the user clicks Clear Data will the data in the datagrid disappear or not?
For showing grid with no rows, check GridView.EmptyDataTemplate Property
or
You can create an empty row and add to your datagrid like this -
if(datatable.Rows.Count == 0)
{
datatable.Rows.Add(datatable.NewRow);
}
datagrid.DataSource = datatable;
datagrid.DataBind();
According to your comment, the answer is No.

How do I programatically put telerik rad grid in "add new" mode on page load

Seems like this should be easy but I must just be missing something... I have a Telerik RadGrid on a page that allows inline editing. How do I programatically put the grid into edit mode to insert a new row into the grid. When the page loads I would like show the existing data and also display 1 empty row that a user can easily type into to add a new record to the table. (I don't want them to have to push the add new button)
Found the answer while back.... updating this in case others need it
RadGrid1.MasterTableView.IsItemInserted = true;
RadGrid1.Rebind();
Lifesaver!!
You can set
radGrid1.MasterTableView.IsItemInserted = false;
radGrid1.Rebind();
that will remove the inserted item (like pressing cancel).
If you need show inset form always you can use next:
protected void NeedDataSource(object sender, GridNeedDataSourceEventArgs e) {
parametersGrid.DataSource = data;
parametersGrid.MasterTableView.IsItemInserted = true;
}
You could try using jQuery to press your add button once the page is ready.
Something along the lines of -
$(document).ready(function() {
$("#addButton").click();
}
What I did when I wanted to do the same with the Telerik grid is to set the MasterTableView.IsItemInserted property of the control to true inside the OnNeedDataSource event handler. I suppose that it should work if you set the property inside the OnDataBound grid handler as well.
Dick
RefreshGrid(userName, "priority", true, false);
RadGrid radGrid = RadGrid1;
radGrid.MasterTableView.InsertItem();
radGrid.Rebind();

Resources