Setting tabindex in dynamic table vertically then horizontally - c#

I have a page that is currently generating dynamically created textboxes in a table format. The users are requesting that the tab order be changed from horizontal-vertical to vertical-horizontal. I know that you can use the tabindex attribute to control the tab ordering, but I can't for the life of me figure out the right way to get the sequential number properly for the textboxes. I guess this is more of a math question than anything else!
FYI, the textboxes are made while looping two different collections. First collection looped to make the rows, for each row, second collection (which is a property of the first collection objects) is looped to create the columns.
Any help would be greatly appreciated. Thanks!

You will need three variables to get this to work:
Total number of rows
Current row index
Current column index
You can then achieve the vertical tab order by setting the tabindex to:
totalRowCount * currentColumnIndex + currentRowIndex + 1
For a five-row, three-column table the above calculation would render the tab order as:
1 5 10
2 6 11
3 7 12
4 8 13
5 9 14
Updated: Wil, thanks for pointing that out. I've updated the example. I also checked the W3C spec (which I probably should have done first) which clarifies the behavior:
elements that do not support the
tabindex attribute or support it and
assign it a value of "0" are navigated
next. These elements are navigated in
the order they appear in the character
stream.

Related

I need a multi-column control that only displays one column in c#

In my project I need a control that allows me to enter 2 columns.
First column is an Id Number
Second column is some Text.
Example...
row 1 Id = 1 Text = Day Shift
row 2 Id = 2 Text = Night Shift
But I only want to display the Text Values and then have the user select either Day Shift or Night Shift.
The program can then just lookup the corresponding value (1 or 2) for whatever text they chose.
- In Microsoft Access I would just have used a ComboBox and hidden the first column.
I cannot find anything in Visual Studio 2017 to put on my Windows Form that easily does this.
I want to set it all up at design time and the closest I have come so far is by using a LISTVIEW control using a display type of LIST (I don't want column headers either.
It seems to do what I want except that it always wants me to leave a blank space below my lines of text - presumably for a horizontal scrollbar even though I set it to False in the properties and it does not actually display a scroll bar.
If I resize the ListView control to just be big enough for my two rows of text it tries to display the 2nd row next to the 1st row and still leaves a blank space below the rows.
See the below images, assuming I uploaded them properly, I am totally new to asking questions here.
Is there a way I can achieve this - should I be using a different control?
The closest I came to what I need is the top image
[![enter image description here][1]][1]
Thanks and I hope it all makes sense.
In reply to Harry I added the below...
After adding the ListView control to my form I then clicked on the little arrow selector (in the top right of the ListView control).to bring up the collections list popup box.
It is there I set the view to be ‘List’ so I don’t have to have column header, then I clicked on EDIT ITEMS to get another pop-up screen…Click the [Add] button to add items in the rows.
Then I changed the Text to ‘Day Shift’ for the first member (and ‘Night Shift’ for the second member).
To add values in the rows for the 2nd column I then clicked the SUBITEMS (collection) box in properties to get the next popup…
I then clicked the Add button and created a new Text item (value 1)
and repeated this for the Night Shift member but gave it a value of 2.
These values are to be the actual ID values (in the 2nd column).
Note…
I did create column Headers but setting the View to List means I don’t get them displayed (and don’t want them displayed).
but I did notice that changing the View to List also removes the second column (Id) from the ListView display.
As I don’t need the Id values (1 & 2) displayed I am not going to worry about what happened to them disappearing in the display. All I did, though, was just changed the View from Details to List.
Sorry If I’m misunderstanding you but at this point there is no actual code I am creating, no doubt Visual Studio 2017 does that itself but I am not looking at that. Is that what you needed to see?
Hope this makes better sense though, I did try and include images but the system will not let me do that until my reputation points are higher, sorry.
Thanks

Set Row Count of Grid Control in WPF

I have a very large dataset(can be up to 3 million items) that I am retrieving on demand based on the scroll position of a grid. This means that I will never have all the items in one collection. But, I need the grid to be interactive and allow the user to scroll as if all the items were in memory.
So, I need a way to set the amount of rows (data items) so that the scroll bar will be the proper size for my database collection. I know the total number of items in the database, so I just need to set the total number of rows in the grid to match that number.
Is there a simple way to do this in WPF with a Datagrid or GridView?
Edit: The important thing is that the scroll bar is properly sized. That way the collection can be indexed based off of it.
Use event handlers for several button controls to make buttons: Next, Previous, First, Last. Parameterise the SQL called by these buttons with firstrow and lastrow inputs say 1 to 10. Each time Next is called, the SQL will spit out the next 10 rows. The rows on the grid per page will be equal to 10 in this case.

how to get 2 lines in datagrid or which control to use in Winforms. so in stead of 1 line use 2 line

I like to have 2 lines (rows) in datagrid, which is together. So normally in a grid you have 1 line per row and every next line/row is independent... But I like to have 2 lines. e.g. 1st row the name,address and 2nd line some amounts, or dates.... so every 2 line is together..
what control do I need to use in Winforms to achieve this... I'm newbie, so I prefer simple solution...
e.g. below I like to use (amount fields should be shown on next line in Datagrid)
DocNumber DocType DueDate SupplierNo SupplierName
Amount VATAmount Total Amount
10000 SA 01-05-2012 1025 Supplier-A
12.25 0.25 12.25
10001 SA 12-12-2014 1095 Supplier-B
42.25 5.25 47.00
10002 SB 31-11-2012 1099 Supplier-C
152.25 55.25 192.00
You could add an extra column to your data (i.e DataTable, for instance) where you specify the row order, and then hide it in your control (a DataGridView for instance).
However this has several drawbacks the first one that comes to mind is that if you click on column headers to sort the grid contents, it will not preserve the order of your rows.
Hope this helps.
Well sounds like to me you need to "group" your data if that's what I'm reading right.
However if this is the case I'm afraid Winforms DGVs do not support this as default as far as my understanding is.
I found this link but havent tried it, looks to be a possible work around/hack for it.
Group Functionality for Winforms Datagridviews
On the plus side there are alot of 3rd party options such as:
Telerik Controls
Or my Personnel favorite :
DevExpress Controls
Beware though even though u can do trials, You may have to pay for publishing, but worth a look!
Hope this helps!

TableLayoutPanel fill top-to-bottom instead of left-to-right?

Is it possible to have a System.Windows.Forms.TableLayoutPanel fill a column before moving to the next one? Regardless of how I set the RowCount, ColumnCount, and GrowStyle, the table is always populated like this:
1 2 3
4 5 6
and I want this:
1 3 5
2 4 6
Can a TableLayoutPanel not automatically do this?
Edit - To clarify, I am adding the controls programmatically.
Not much you can do about it. It's just how TableLayoutControlCollection.Add is implemented internally. I see two options:
Use TableLayoutControlCollection.Add(Control, column, row). But that's quite a hassle, because you need to calculate the column/row values each time you add a control.
Create a derived control that overrides Add and implement it as the overload above - but now internally.

Crystal Report Making on the basis of Number of Selected Attributes from check list, how can we do so?

I am developing application in C# Windows Forms, i make crystal reports on the basis of data collection list in c#, for example i have a table having EmpID, Name, Sponsor, Job Title, Nationality etc. I bring them in collection in c# and pass it to crystal report, where i see my attributes in Database fields, if i drag and drop those fields on the report, for example Name, Job Title, Nationality, then i can see their columns coming in Details section, but the issue is, i have about 25 attributes and i have made a check list of 25 attributes in c#, if i check 13 attributes, it should make a report of 13 columns, the problem is, we make report in crystal report on the basis of drag and dropping fields, how can i dynamically do this, means if there are 13 fields selected in c# check list, there should be just 13 columns in report. Please find the image attached, "How currently i am doing" Please zoom it by right click on it, and open in new window.
I think that the easiest way to approach this, considering data type representations and all of the Crystal complexity under the covers, is to layout your report with all 25 fields sized appropriately.
Then, at runtime, you will need to reposition the report objects, which could be a little tricky due to the relatively unstructured way in which crystal provides the information.
The way I would approach this is to loop through the report objects and generate one SortedList for the data fields and one SortedList for the header fields. They should be sorted on their Left position so that you can process them in appearance order.
Once you have the sorted lists of objects, you can cycle through each one and, if it was not selected by the user, set the Width to 0.
As you are moving through the fields, you will keep track of the current left position. The first field that you process will set your starting point, even if it is not visible. Then, for all subsequent fields, if the field is visible, you will set its left value to the current left position, then add its width plus some separator space to the current left position for the next field.
Hopefully this will help you solve your problem.
It sounds like this would be a good place for a cross-tab report. In this case you'd need to add a cross tab to your report header or footer and pass your data into the report with a column for each attribute descriptions and then group on the attribute description. See below for details:
Data:
RowID ColDesc ColValue
1 Attr1 Value1
1 Attr2 Value2
2 Attr1 Value3
Then you can add your crosstab where your row field is RowID, your column field is ColDesc and the field to summarize is ColValue. You can use a Max of summary on the summarized field since it is different.
This is untested, but I believe that the output for this should be:
CrossTab:
Attr1 Attr2
1 Value1 Value2
2 Value3
As you can see that as you add a new attribute it will show up as a new column in the crosstab. As I said previously, this is untested so I apologize for any errors, but I hope it is enough to help you out. Thanks
Give a look at these links
http://www.c-sharpcorner.com/UploadFile/uditsingh/CR1111022006055359AM/CR11.aspx
http://www.crystalkeen.com/articles/crystalreports/dynamiccrosstab.htm
Using this Google Search
Crystal Reports will not automatically add columns & headers to a report given a list of fields.
My recommendation is to use the Report Application Server .NET SDK to dynamically alter a report. The link includes the API reference, as well as samples.

Categories