We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Problems with ImageAndButton in DataBoundGrid

Hi, I have problem with the ImageAndButton 1. style.VerticalAlignment = GridVerticalAlignment.Bottom; style.HorizontalAlignment = GridHorizontalAlignment.Right; But above code is not working. I want to make button botton and the right side. 2. When I click on delete button, i am setting the style.backgroundcolor=null which is again not working. Please find the sample code. Thanks Satish ImageAndButton_332.zip

10 Replies

AD Administrator Syncfusion Team June 22, 2004 10:55 AM UTC

1) Alignment properties you are setting do not affect buttons. They only affect the text. If you want to position the buttons, then in the renderer class, you will have to override OnLayout and do it there.
protected override Rectangle OnLayout(int rowIndex, int colIndex, GridStyleInfo style, Rectangle innerBounds, Rectangle[] buttonsBounds)
{
	Rectangle rect1 = innerBounds;
	rect1 = new Rectangle(rect1.Right - 81, rect1.Bottom - 20, 40, 20);
	buttonsBounds[0] = rect1;
	rect1 = new Rectangle(rect1.Right + 1, rect1.Top, 40, 20);
	buttonsBounds[1] = rect1;
	return innerBounds;
}
2) You are using a GridDataBoundGrid. You cannot set cell specific properties like BackgroundImage using an indexer on a GridDataBoundGrid. http://www.syncfusion.com/Support/article.aspx?id=560 If you want to use a GridDataBoundGrid and have a style property like BackgroundImage vary cell to cell in the same column, then you will have to provide these values in either a Model.QueryCellInfo event or a PrepareViewStyleInfo event. You cannot set them with indexers.


SA Satish June 23, 2004 01:16 PM UTC

Hi Clay, Please find my questions after done with what you mentioned. Thanks Satish >1) Alignment properties you are setting do not affect buttons. They only affect the text. > >If you want to position the buttons, then in the renderer class, you will have to override OnLayout and do it there. >
>protected override Rectangle OnLayout(int rowIndex, int colIndex, GridStyleInfo style, Rectangle innerBounds, Rectangle[] buttonsBounds)
>{
>	Rectangle rect1 = innerBounds;
>	rect1 = new Rectangle(rect1.Right - 81, rect1.Bottom - 20, 40, 20);
>	buttonsBounds[0] = rect1;
>	rect1 = new Rectangle(rect1.Right + 1, rect1.Top, 40, 20);
>	buttonsBounds[1] = rect1;
>	return innerBounds;
>}
>
> >2) You are using a GridDataBoundGrid. You cannot set cell specific properties like BackgroundImage using an indexer on a GridDataBoundGrid. http://www.syncfusion.com/Support/article.aspx?id=560 > >If you want to use a GridDataBoundGrid and have a style property like BackgroundImage vary cell to cell in the same column, then you will have to provide these values in either a Model.QueryCellInfo event or a PrepareViewStyleInfo event. You cannot set them with indexers. The Current Problem is in executing AddDelete_5027.zip


AD Administrator Syncfusion Team June 23, 2004 02:06 PM UTC

The problem is what I responded to in item 2 above. In a GridDataBoundGrid, you cannot just set cell specific properties other the CellValue using an indexer. So, if you want each cell in your last column to have different BackGroundImages, then you will have to maintain a array (ImageList, hashtable, or some other datastructure) that holds these different images. How you do this is up to you. If your table has 50 rows in it, you could create an ImageList with 50 images in it. They could all start out to be the default. Then when you add or remove an image, you would change the proper image in this ImageList. Or, you could create a Hashtable that just holds keys that point to the cells that do not use the default image, and the values in the hashtable could be teh proper images. Then when you add and delete images, you would add/remove items from this hashtable. Now, once you have whatever datastructure you want to use that hold an image for every row in your grid (or at least, the the structure allows you to get the image you want to see in any particular row), you are ready to try to show these images in the grid. But without the datastructure that provides these images given a row index, your GridDataBoundGrid will not be able to show the images you want. To get the grid to show the image, you use PrepareViewStyleInfo to get the proper image from your datastructure and provide it by setting the image properties in e.Style based on e.RowIndex. The e.RowIndex will be used by you to retrieve the proper image from your datastructure. The grid has no knowledge of these images. You have to create a datastructure to hold them, have code that adds/removes them from this datastructure, and also have code that can retrieve the proper image given a requsted rowindex.


SA Satish June 28, 2004 10:45 AM UTC

Clay, We tried maintaining images in a imagelist.when clicking on add button on the last cell,it calls CellButtonClicked function which in turn calls PrepareViewStyleInfo function which adds the selected image from the list to the current row,column index . But on changing focus to the next row last column the image on this column is also replaced with the last image replaced i.e without clicking on the Add Button(looks like PrepareViewStyleInfo function is stored and keeps executing Add image function on focus to the last column irrespective of the row after the first Add).Could you please tell us how this can be taken care of(if with an example it would be helpfull) Thanks Satish >The problem is what I responded to in item 2 above. > >In a GridDataBoundGrid, you cannot just set cell specific properties other the CellValue using an indexer. > >So, if you want each cell in your last column to have different BackGroundImages, then you will have to maintain a array (ImageList, hashtable, or some other datastructure) that holds these different images. > >How you do this is up to you. If your table has 50 rows in it, you could create an ImageList with 50 images in it. They could all start out to be the default. Then when you add or remove an image, you would change the proper image in this ImageList. > >Or, you could create a Hashtable that just holds keys that point to the cells that do not use the default image, and the values in the hashtable could be teh proper images. Then when you add and delete images, you would add/remove items from this hashtable. > >Now, once you have whatever datastructure you want to use that hold an image for every row in your grid (or at least, the the structure allows you to get the image you want to see in any particular row), you are ready to try to show these images in the grid. But without the datastructure that provides these images given a row index, your GridDataBoundGrid will not be able to show the images you want. > >To get the grid to show the image, you use PrepareViewStyleInfo to get the proper image from your datastructure and provide it by setting the image properties in e.Style based on e.RowIndex. The e.RowIndex will be used by you to retrieve the proper image from your datastructure. The grid has no knowledge of these images. You have to create a datastructure to hold them, have code that adds/removes them from this datastructure, and also have code that can retrieve the proper image given a requsted rowindex.


AD Administrator Syncfusion Team June 28, 2004 11:49 AM UTC

Can you attached a sample project showing what you are trying to do, and what the problem is?


SA Satish June 29, 2004 10:41 AM UTC

Hi Clay, Sorry for not attaching a sample project. Attached is the c# project file using which we are trying to be able to modify a cell content by providing ''Add'' and ''Delete'' buttons. Clicking on ''Add'' Opens a File Dialog to browse for the image to Add(and should update the cell with the the selected image) Clicking on delete Should Delete the image from the current cell. The Problem is encountered only in GridDataBoundGrid Application (as in Form2.cs) But it works fine in GridControl Application (as in Main form form1.cs) (which can be tested by running the Application Form1() in Main()(currently it has been set to Form2()) (Please Note column/image resizing has not been handled in Form2 has to be manually done) Note : Please change the required default images. Thanks Satish >Can you attached a sample project showing what you are trying to do, and what the problem is? ImageAndButton_1735.zip


SA Satish June 29, 2004 11:17 AM UTC

FURTHER NOTE: Please Select the Cell having Add & Delete Button for it to function on clicking. and as told PLEASE CODE CHANGE the default images at Image.FromFile(.... in Form2() AND Image.FromFile(.... in Form1_Load


AD Administrator Syncfusion Team June 29, 2004 11:54 AM UTC

Here is your sample back using a hashtable to hold images for every cell, and using PrepareViewStyleInfo to retrieve those images. ImageAndButton_7637.zip


SA Satish June 29, 2004 01:19 PM UTC

>Here is your sample back using a hashtable to hold images for every cell, and using PrepareViewStyleInfo to retrieve those images. > >ImageAndButton_7637.zip > >


SA Satish June 29, 2004 01:20 PM UTC

Hi Clay, Thanks. Yes its working. great help. Thanks Satish > > >>Here is your sample back using a hashtable to hold images for every cell, and using PrepareViewStyleInfo to retrieve those images. >> >>ImageAndButton_7637.zip >> >>

Loader.
Live Chat Icon For mobile
Up arrow icon