Multiple columns in List box control - c#

How can I display two columns in a list box?

A list box wasn't designed to display multi-column data. Even the Windows Forms version doesn't directly support that kind of data display.
Your requirements aren't clear, but the simplest way to go would be to use a GridView control. It gives you a lot of functionality out of the box, and you can expand it to more columns very easily. If you need more control over the look or functionality, you can use a DataList instead.
To get the scrolling ability, you can either use a scrolling <div> or simply use the pagination mechanism of the GridView if that's appropriate.

You could line it up as if the data was in 2 columns
new ListItem("blah1".PadRight(10, ' ') + "blah2");
as shown here: http://articles.dotheweb.net/post/Formatting-columns-in-a-ListBox-of-ComboBox.aspx
Also, you could roll your own with a DataList.

If you want to use columns in a ListBox, you have to do it based on alignment.
For example:
String columns = "{0, -55}{1, -35}{2, -35}";
ListBox1.Items.Add(String.Format(columns, "Filename", "Selected DateModified", "Vault DateModified"));
ListBox1.Items.Add(String.Format(columns, fileName, datetime1, datetime2));
Output of my own implementation of this code below:
Keep in mind the font you use has to be a monospaced font, otherwise the alignment will mess up due to variable spacing between characters (and this exaggerates the longer the string is).

Looks like you should write your own control, or you can use the listview control.

As Nick Craver has already commented, the ListView probably isn't the right control for multi-column information.
Instead of hacking your list to appear as if it has two columns, it might be a better idea to use a DataGridView. It'll be easier to setup, format, and your data will be held in a much more flexible way.
DataGridViews also support assigning Lists of objects as datasources, if that makes things easier.

use list view it is perfect alternative for multi column list box

If I understood correctly, you want a data column to display horizontal. This can be acheived by using a DataList and have RepeatDirection set to "Hozizontal" with the specified repeat columns.
Eg :
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="5" CellSpacing="10" >

Multiple items side by side are possible if you reference the toolkit and add the wrapPanelOrientation ;)
it will list look like
1stItem 2ndItem
3rdItem 4thItem .. ect..
ListBox.ItemsPanel>
ItemsPanelTemplate>
toolkit:WrapPanelOrientation="Horizontal"FlowDirection="LeftToRight"ItemWidth="220"ItemHeight="60"/>
/ItemsPanelTemplate>
/ListBox.ItemsPanel>
/ListBox>

Related

Infragistics StackColumnChart show the wrong value

I need an explanation about Infragistics, which I don't understand. I want to display several bars in a chart per month. The whole thing will be in my opinion a StackColumnChart:
But is displayed incorrectly.
If I run the whole thing as a ColumnChart they are displayed correctly:
Is it possible that I get the same display also in the StackColumnChart?
Actually your chart is configured to show data values on charted items. This is how the data is organized on the Stacked Column Chart. But this default behavior you can change according to your requirements.
Make the following changes.
I suppose you already have the Infragistics.UltraChart.Resources.Appearance.ChartTextAppearance chartTextAppearance1 declaration. If not you can add it by using the Chart Wizard.
The chartTextAppearance1 will added later to the column chart appearance like that:
columnChartAppearance1.ChartText.Add(chartTextAppearance1);
Set the chartTextAppearance1.ItemFormatString to <DATA_VALUE_ITEM>:
chartTextAppearance1.ItemFormatString = "<DATA_VALUE_ITEM>";
This make it work as you was asking.
Some additional information you can find here: Label Formatting

How to generate freeform rdlc reports with one page per row

Given a data set containing multiple rows, from within a .NET console application I need to generate a report on a single page for each row, sending those pages directly to the printer.
I am attempting to use Microsoft Report for this by attaching it to a data set and placing TextBoxes where I wish. Generating the report and sending it to the printer are not a problem. Unfortunately, the data only seems to be available in aggregates -- First, Sum, Last, Max, etc. I cannot latch the text box to a bare field.
Some poking around here and other sites seems to address this, but only when the data is presented in a table. One post even said without elaboration, "My mistake was using Text Boxes"
Am I using the wrong tool for what I am attempting to accomplish?
I ran into the same problem and managed to solve it. The solution seems a little convoluted to me so don't quote me on the "right" way to do this, but here is what I did:
Make sure you have a Dataset defined for your report.
Add a "Table" control to the report. This seems to be needed in order to iterate the rows in your Dataset.
Delete the header row and two of the default columns from the table so that you are left with a single row with a single column.
Expand the table to the width of your layout and make it as tall as you will need for your "free form" layout.
By default, there is a TextBox inside the table cell. Right-click the empty table cell and choose "delete" to remove that TextBox.
Drag a "Rectangle" control into the empty table cell. It seems to automatically "dock" to the width/height of the table cell.
Now you should be able to drag the fields from your DataSet (TextBoxes, etc) into the Rectangle to produce the desired layout.
Note that I am in the early stages of using this approach so I'm not sure if I am going to hit any walls... but for a basic report that uses TextBoxes and a page break after each "row" it seems to be working ok.
Or you try to use a list.
In the list you can arange textboxes (and other controls) as you want and they will be filled for each record in the recordset.
This work for me. :-)

How to remember formatting options for cells in a gridview

I'm using a GridView that is bound to an object (an entity). The grid can be filtered and otherwise customized in terms of the data it shows. The rows, columns and more specifically cells will be formatted using some rules, but also from the user specifically setting formatting options.
My questions is about the best way to recall the chosen formatting for specific cells. Currently my best method is to store an id for each cell that looks up all of the formatting for that cell (i.e. ForeColor, BackColor, FontWeight etc).
Another way would be to create a new table (called say Formatted_Cells) that stores the id and column name of the table in question, and then the formatting options. This would involve checking the Formatted_Cells table each time a cell is processed to check for formatting. It is quite a bit of processing (similar to the above method). If I did this I could flag any rows that have custom formatting, and if they do not I wouldn't need to check the Formatted_Cells table which does provide an advantage over remembering formatting for EVERY cell, when the vast majority will not have any custom formatting.
Is there a better way? I don't think I can use Serialization to help as the grid is loaded from the database which may be modified elsewhere. But perhaps I'm missing something obvious?
Much appreciated.
I'd suggest an additional table also.
Two possible solutions come to mind:
1- Do the formatting in two passes. First load the grid normally, then read Formatted_Cells table from database, find styled rows in grid and apply special styling.
2- When quering database for Cells, add Formatted_Cells table with left join. When loading grid, check for additional columns that might come from left join, apply those. If no additional columns, style normally.

Get the number of rows which contain a certain value in one of the columns and display the number in a label

I have a gridview and sqldatasource.
I want to display in a label, the number of rows from the gridview which contains a certain value in one of the columns (in the form_load event)
I thought about looping through all columns of the gridview but it will take a lot of time for this and maybe there's another way of doing this.
Can someone help me finding the "other way"?
Thanks,
Best solution would be to let the database handle filtering - you'll get much better performance that way than looping over the data on application server.
Perhaps create another SqlDataSource with an SQL statement containing appropriate WHERE condition and bind it to your label?

Showing records on grid efficiently

i have a third component grid that i am using on my page.
It displays 20 records in one page.
Also i am using images to display certain columns.
Like comments , attachements have clickable images for every row.
the problem is.. everytime i load my page.. the logic right now is.. it goes in the database.. checks for every row in the table to see if the comments are added or is there attachment.. and accordingly disables or enable the image of that particular record(row)
Now this takes too many database hits and processing time increases.
Can u tell me any other way to do this.?
You could add a column "Number of comments" and "Number of attachments" to your rows.
You should enable some sort of VirtualMode in your grid ( every grid should have this function in some way ) in order to feed just the item the user actually see. This is a good practice always.
Irrespective of grid, you can build some sort of object which collectively holds the textual information that you need to show and some more flags which tell you about the image and attachment. You bind the collection of this custom object to your grid.
Use the flags in this object to put different images in your columns.
HTH

Categories