473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Add Controls to ListView

Hi All,

Is it possible to add other controls to the ListView control in C# windows
forms. i.e. I want to add a button column so to speak to the list view. You
can do this sort of thing with the datagrid in asp.net, however I think the
datagrid in c# is overly complex for what I'm wanting to do, and I'm not
even sure it is possible to do it in that.

Answers to both Controls would be appreciated.

Thanks

Alan
Nov 15 '05 #1
1 10445
Hi Alan
Yes you can add a button column to datagrid control. You can then write
event to handle clicks on that control ( in the event handler of…….. you
can handle event according to which button column was clicked… and on
which row if the datagrid it was clicked … and her is an example
First , you will add the datagrid control to the aspx page as follows
<asp:datagrid DataKeyField="DiscId" id="DataGrid1" style="Z-INDEX: 110;
LEFT: 8px; POSITION: absolute; TOP: 408px"
runat="server" AutoGenerateColumns="False" CellPadding="8"
BorderWidth="2px" BorderColor="Yellow">
<HeaderStyle ForeColor="White" BackColor="Indigo"></HeaderStyle>
<Columns>

<asp:BoundColumn DataField="FloatDiscNumber" SortExpression="DES"
HeaderText="FloatNumber">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="PackDescription" HeaderText="Catagory">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>

<asp:ButtonColumn Text="Book" ButtonType="PushButton"
HeaderText="Reserve" CommandName="reserve">
<ItemStyle BackColor="Purple"></ItemStyle>
</asp:ButtonColumn>
<asp:TemplateColumn HeaderText="DVD View">
<ItemStyle BackColor="Purple"></ItemStyle>
<ItemTemplate >
<asp:Button runat="server" Text="Details" CommandName="opencontent"
CausesValidation="false"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

Then inside your code you define a handler to the datagrid ItemCommand
event as follows

private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName.Equals("reserve"))// here you know
// which button column was clicked
{
disks.row.PrimaryKey = new DataColumn[]{disks.row.Columns["DiscId"]};
DataRow row =
disks.row.Rows.Find(DataGrid1.DataKeys[e.Item.ItemIndex]);which column
//was clicked
//do some stuff here
}
else
{
disks.row.PrimaryKey = new DataColumn[]{disks.row.Columns["DiscId"]};
DataRow row = disks.row.Rows.Find(DataGrid1.DataKeys[e.Item.ItemIndex]);
//do some stuff here
}
}
Hope this would help

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Terrance | last post by:
I'm hoping that there's someone out here that can help me with a coding problem. Here is the scenerio: I have a MdiParent Form on this MdiParent form there is a listview control and several text...
2
by: John R. | last post by:
I want to have a listbox that shows a checkbox and a textbox. I created a user control that has a checkbox and a textbox in it and have been trying to add it to a listbox but I can't get it to...
6
by: Josef Brunner | last post by:
Hi, I have a problem using two ListView controls on one and the same form: Problem: The second ListView is never focused. No matter where I "click" non of the items within the ListView is...
7
by: Alexander Walker | last post by:
Hello I want to get the value of a property of a control from a thread other than the thread the control was created on, as far as I can see this is not the same as invoking an operation on a...
9
by: Dimsion | last post by:
Hi, How do i expose all my forms and it controls to other form in the project? I want to be able to add a form and some control on it, this then be available to all other forms. form1 click...
0
by: Charles Law | last post by:
Can anyone suggest how to keep two ListView controls synchronised? It is a common scenario: two ListView controls, side-by-side, containing similar data. I want to scroll one control and have the...
2
by: Sin Jeong-hun | last post by:
I often use detail view of the ListView control to display tabular data (is there any better way?) Many real-world applications display buttons, progress bars or dropdown lists in the columns, but...
1
by: jmDesktop | last post by:
Consider: Private Sub ListView_ItemDrag(ByVal sender As Object, ByVal e As _ System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag, _ ListView2.ItemDrag in VB. Can this be...
0
by: Jarppi | last post by:
Hi All, Not sure how to go about this one. I've got a windows form with five ListView controls, each listing the files in a seperate folder. What I want to achieve is this: When I scroll any...
4
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I have just started building an application which is windows form based, rather than web based, and I am having troubles with layout. I can't find any control which gives me just a simple text...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.