This is a migrated thread and some comments may be shown as answers.

Adding image button into grid

2 Answers 315 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shane P
Top achievements
Rank 1
Shane P asked on 31 Aug 2009, 11:33 AM
Hey everyone.

I am upgrading my skills into winform development from asp.net and need a little help....I think asp.net is much easier when it comes to grids and data layout....but hey its only early days.

I have created a grid and I am wanting to add a couple of buttons to the right of the actual data however I am struggling...I dont want to use standard buttons I want to use images and have an onclick event on each of them.

My binding class looks like this

 public ItemDetail(int itemID, string itemDescription, int itemsRequired)  
        {  
            ItemID = itemID;  
            itemDescription = itemDescription;  
            ItemsRequired = ItemsRequired;  
        }  
        public int ItemID { getset; }  
        public string ItemDescription { getset; }  
        public int ItemsRequired { getset; } 

Within my win form I have this

  public List<ItemDetail> _itemDetails = new List<ItemDetail>();  
 
 
       
        public MainForm()  
        {  
            InitializeComponent();  
       
 
            BindItems();  
             
          
             
        }  

private

 

void BindItms()

 

{

gridItems.DataSource = _itemDetails;

 

GridViewCommandColumn addColumn = new GridViewCommandColumn();

 

addColumn.DefaultText =

"Hello";

 

 

RadDataGridViewButtonColumn buttonColumn = new RadDataGridViewButtonColumn();

 

buttonColumn.Text =

"Press Me";

 

 

 

this.gridItems.Columns.Add(addColumn);

 

 

this.gridItes.CommandCellClick += new CommandCellClickEventHandler(gridItems_CommandCellClick);

 

}


 

If I run the above code it a runs fine....As you can see I have tried adding buttons....
What do I need to do to add the columns.....Ideally when I pressed either of them they would return the selected item ID i.e ItemID


Sorry if this is all asic stuff however still getting my head around win forms

Thank you for your help

2 Answers, 1 is accepted

Sort by
0
Accepted
Robert
Top achievements
Rank 1
answered on 31 Aug 2009, 03:01 PM
Hi Shane,

I think this forum post describes what you are looking for. On it, there is an example program that describes how to add an image to a GridViewCommandColumn.

You should be able to get the ItemDetail for the clicked row by doing the following:
        void radGridView1_CommandCellClick(object sender, EventArgs e) 
        { 
            ItemDetail detail = (ItemDetail)(sender as GridCommandCellElement).RowInfo.DataBoundItem; 
        } 

I hope this helps.

- Robert
0
Shane P
Top achievements
Rank 1
answered on 31 Aug 2009, 10:24 PM
Thanks Robert that was what I was after!
Tags
GridView
Asked by
Shane P
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Shane P
Top achievements
Rank 1
Share this question
or