Insert Data Into Listview And Save To SQL Server - c#

am using C#, VS-2005
am new for listview Control in VS-2005. I know how to Insert Records into Listview by typing on Outer Textbox.
But don't know how to directly insert Records on Empty ListView control as it not Focus It's Self.
If any other way or is it possible to insert data directly to ListView Control then Please provide me some code or guide me please.

If you refer to WinForms, see the System.Windows.Forms.ListViewItem Class,
it Represents an item in a ListView control.
ListViewItem class defines the appearance, behavior, and data associated with an item that is displayed in the ListView control. ListViewItem objects can be displayed in the ListView control in one of four different views.
From the example on the same page (see the full example using the ref above):
ListView listView1 = new ListView();
...
ListViewItem item1 = new ListViewItem("item1",0);
...
listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});

It sounds like you want a grid control rather than a Listview control. In my experience, Listview controls are primarily read-only and grids are editable. Have you considered using a grid?

Related

Programmatically create table with clickable and expandable content in WPF

This is what I desire to create:
As you see I need to create table like control with images and clickable cells. When you click on an arrow on the left it expands its' content and content contains some more additional table like controls with data. Also when user clicks on a Star I need to add this event to Favorites list and etc.
Currently, for each data row I'm thinking of programmatically creating accordion item with Grid in header for images and cells and other Grids for the content.
What is the best and easier way to achieve this task? What controls should I use? I need some suggestions, as I'm new to WPF.
WPF DataGrid can show RowDetails. Customize them with RowDetailsTemplate property and manage their visibility with RowDetailsVisibilityMode property

WPF - Display db records into a list

I am quite new to WPF and XAML but my background is of ASP.NET and C# so I have a vague idea of how it works.
In .net, I can use the repeater, datalist, gridview, bind to them a DataTable and output from that DataTable. I am now wanting to do the same with WPF.
Basically, I want to display simple records from a database (preferably using a DataTable as I usually work with those). The list might be something like this with two columns
1) Grey TV
2) Red car
3) Blue motorbike
I have looked around but I can't get a definitive answer on what control to use. Some people say ItemsControl and some people say DataGrid. Can anyone help me here?
Thanks in advance.
A DataGrid is used for displaying Table-like data (Per record multiple columns). An ItemsControl is used to display data using your own ItemTemplate, in which you are unlimited in how to represent the items and in what directions or alignments.
Another good useable control for you might be a ListView, which works just as a ListBox except it doesn't have any selection logic. And you can choose between four different ways of displaying your items using the View property (http://msdn.microsoft.com/en-us/library/system.windows.forms.view.aspx).
In your case I would suggest using a ListView.
To bind any items to the control, you have to set the DataContext on the UserControl or the Control itself. And then bind the ItemsSource property to a local List or Collection using the Binding markup extension (http://msdn.microsoft.com/en-us/library/ms750413.aspx). To learn more about data-binding go here:
http://msdn.microsoft.com/en-us/library/ms752347.aspx

Adding image to the Listview subitems [ windows forms ]

I'm doing project in windows forms using c#.
I want to show an image in the listview subitems.
For eg:-
There is a listview having 3 Columns (Column 1 is Roll number,Column 2 is StudentName,Column 3 is StudentPhoto) .I can use the ListViewItems to add Items in the ListView.
Adding First items to the ListView,
ListViewItem item = new ListViewItem("101");
item.SubItem.Add("Robin");
SampleListView.Items.Add(item);
Now i'm having difficult in Showing StudentImage in the 3rd column,Can anyone help!
Note:
Also i have ImageList assigned to SampleListView.
ListView does wrap the native list view control from common controls of Windows. This control does not directly support images on subitems. You need to set the listview it to owner draw to let you handle the drawing.
Luckily others have done this already. On CodeProject there is a good one.

How do I display two tables in a data grid/tree view showing columns for both the parent and child tables (when child expanded)

I'm trying to use a TreeView/DataGrid to display some data. I need to display columns for the top level items, but also display a header for the expanded level.
I have a dataset with two tables, e.g. Orders and Items, items has a foreign key to Orders.
I'm trying to bind the dataset to the datagrid/tree view so that I show the list of orders.
The WinFrom DataGrid can show multiple tables from the DataSet:
Which I set with:
dataGrid.DataSource = dataSet;
dataGrid.DataMember = "Orders";
Clicking the [+] expands the row to show the link:
Following that link brings up the Items Table:
What I'm after is a mix of both but in WPF:
I've used a dataset for this example but I can massage my data into collections etc that WPF can use to display the data in the way I'm trying to achieve.
I've looked at the TreeListView which gives me the top level item headers, but I'm scratching my head trying to get the expanded items header to be shown. Could someone point me in the right direction, thanks.
Update I've come back to looking at this issue. As per #offapps-cory's answer I tried using a ListView with expander with a listview. 1st attempt:
As you can see, it expanded in the cell :) I'm thinking maybe I can throw a treeview into the mix...
Could you instead use a ListBox with ListViews nested in the items? While I have not had ListViews nested, I have nested ListBoxes several levels deep to achieve some functionality that I needed.
I originally thought that one might do as you are asking by customizing the TreeViewItem template and the ItemsPresenter, but ItemsPresenter is expecting a Panel, and ListView is a control.
I would try creating a DataTemplate with a ListView/GridView in it and an expander. You may need to do some funny databinding to get it working, but I don't see why it wouldn't work.

adding a control to tabs generated dynamically in tabcontrol in C# .net

I am new to C# .NET.
Can some one help me out with the below problem:
I have a TabControl in my WindowsForm application, where the tab pages are generated dynamically. The content to be displayed on each tab would be fetched from my database. I need some kind of control (which can display the fetched data) that I can add on each tab page (which would be same for all tabs) such that I can associate some kind of event, say click, on that added control.
Can anyone tell me how to do this programmatically & write the click event for all the controls added?
Please refer the below link! You will get more detail in this regard.
Creating a tab control with a dynamic number of tabs in Visual Studio C#
I'm not sure I completely understand your problem but my initial thoughts are that you could dynamically create a datagrid or something similar for each tab that you are dynmically creating. You could then bind the datasource for the grid and then add the grid as a control to your tabpage.
Something like...
DataGridView gv = new DataGridView();
gv.DataSource = //whatever your source is
this.tabPage1.Controls.Add(gv);
You would then have all the events associated with the grid to work with.
I'm thinking data binding is going to be your best bet for displaying this information. You can create a list of objects and use a DataTemplate to format the data. You can apply the DataTemplate to a quite a few objects. I generally use the ItemsControl and ListBox
http://msdn.microsoft.com/en-us/library/ms750612.aspx
good luck

Categories

Resources