I want to create custom file dialog box with several validations. So I've chosen list box with multiple columns. I want to show all files of a specific location in this list box with horizontal scroll bar. I am facing a problem. I want to set the column width property to Auto so that if a file has longer name the column width automatically increased accordingly. I didn't find any "Auto Width" property, so I have to manually put the width of the column. I am stuck by this problem.
Please help me to resolve this problem.
Take this pseudo-code and use listbox graphics to measure string (http://msdn.microsoft.com/en-us/library/6xe5hazb.aspx)
int colWidth, nextWidth;
foreach (string file in files)
{
nextWidth = MeasureFileName(file);
if (colWidth < nextWidth) colWidth= nextWidth;
// Add file to list
}
// set column width here to value in "colWidth"
Related
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
I've been trying to create Mp3 list using DataGridView to show info. I want to add data at runtime and I have Columns like Artist, Song Name, Rating, Path... but I want to be able to select entire Row when selecting a Cell. I've used this code for that:
private void DataViewGrid1_MouseClick(object sender, MouseEventArgs e)
{
int rindex = DataViewGrid1.CurrentCell.RowIndex;
DataViewGrid1.Rows[rindex].Selected = true;
}
and it works but the problem is that it's to sloooow! When I click on the cell whole row is selected but it's visually terrible. I can see cell selected and after a delay whole row is selected but the delay is just too long. Is there a faster (or better) way to do this? Or maybe there is a better control that can do this? I also want to be able to present rows in a different font (for example: change font color for the same artist in the list).
I'm open for all suggestions.
Thanks!
DataViewGrid1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
The entire row will be selected by clicking its row's header or a cell contained in that row.
If you want to color based on having a value in the cell, something like this will do the trick.
I am trying to automate my C# application, and part of that includes selecting a file inside an open file dialog. Once the window opens, I am able to grab the necessary UI element (a combo box) but cannot set the value to the file name that I want.
I believe this is because the combo box is empty in the beginning (i.e. I have never used this function manually and selected the file, so it is not stored in the combobox). Is there a way I can programmatically add an item to the combobox before selecting it? Here is my current code:
var fileUploadWindow = Program.application.GetWindows().Where(win => ((win.Name == ("File Upload Directory")))).FirstOrDefault();
var fileNameComboBox = fileUploadWindow.Get<ComboBox>(SearchCriteria.ByAutomationId("fileComboBox"));
fileNameComboBox.SetValue(fileName);
var openButton = fileUploadWindow.Get<Button>(SearchCriteria.ByAutomationId("openButton"));
openButton.Click();
Using this, when I call the SetValue() function, I receive an error:
Item of text 'fileName' not found.
How can I check to see if the file name is inside the combo box, and insert it if it isn't?
I would like to (if possible) handle this in the automation, without having to change the application itself. I also prefer to be able to insert the text into the combobox directly, instead of automating the file picker.
I found the solution.
As it turns out, an editable combo box can also be retrieved as a TextBox. So all I had to do was change two lines of code:
var fileNameTextBox = fileUploadWindow.Get<TextBox>(SearchCriteria.ByAutomationId("fileComboBox"));
fileNameTextBox.Text = fileName;
I have a C# WPF Application where i use a DataTable as Source for a DataGrid.
Now when The User moves a Column in the DataGrid(I already found a ColumnReordered Event)
I want to change the index of the Column to the Position,
that the User moved it to(0 for the first position, 1 for the second...)
I want to do that because i want to save the column positions for the next time the User runs the Apllication.
Is there any possible way to do that?
All you need to do is whenever user is about to close the form you get the column name and its respective index and save that to any format like xml, csv. Next time when user loads you can apply the re-oredering after reading his last specified settings from the file.
You can have a look at this article for what i mean. This implements the same idea. You can modify it for your WPF application though.
http://www.codeproject.com/Articles/37087/DataGridView-that-Saves-Column-Order-Width-and-Vis
Use the ColumnIndex
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
Post that is already on here should help;
Get current cell column index in DataGridView CurrentCellChanged Event
I have a combo-box which contains different names of files and every time i select a value the respective file should be read and respective graphs should be generated. Now as i select the first file the charts are drawn correctly but if i select another value from the combo-box then the charts instead of re-plotting the charts values are added to the existing values..
I tried using serializer but that doesn't seem to work...neither i am able to find a solution anywhere.
Just need to know what i need to add as to reset the existing chart to default value and redraw on every combo-box selection.
You'll need to clear the values from each of your Series.
chart.Series["MySeries"].Points.Clear();
foreach (var series in chart2.Series)
{
series.Points.Clear();
}