Windows Forms Listbox Multible Lists in same Box - winforms

I'm working on a project where I'm getting a list of contacts from a webservice. These contacts have names and emails and each of thoose I save in a list of strings. Now I want my listbox to take in the names and the emails and write them in 2 columns. Then I want to be able to select one set in the listbox and get the email or name in that set. My problem is I cant find a method for doing the multicolumn thing. The only thing I've found is the Listbox.MultiColumn attribute but it seems to take 1 list and just divide it into more columns.
Thanks in advance

ListBoxes don't support multiple columns (MultiColumn just spreads the existing items across columns, as you have seen)
An alternative would be to use a ListView set in Details mode instead, and add each column as a SubItem as in this question.

You can use DataGridView
You can add rows like this:
string[] row1 = new string[] { "Column 1", "Column 2", "..." };
string[] row2 = new string[] { "Column 1", "Column 2", "..." };
// And so on
object[] rows = new object[] { row1, row2 };
foreach (string[] row in rows)
{
yourDataGridView.Rows.Add(row);
}

Related

Pre-fill with the id of an entity

How can I pre-fill a new content with an entity relationship that I know the id? I know the item is, let's say 1234, but if I use this number like that :
#Edit.Toolbar(actions: "new", contentType: "NewsItem", prefill = new { Category = 1234 } )
It doesn't work. When I implement the code above, the form for a new item shows up but instead of having the correct item selected, I have (item not found). Obviously, my argument is not correct. So, how do I code this argument?
I also tried
Category = {1234}
Category = new {(1234}}
Category = "1234"
But nothing works. Any ideas?
We're working on enhancing this, but as of now, you are best off using the guid - as shown in the wiki: https://github.com/2sic/2sxc/wiki/razor-edit.toolbar#multiple-entities-prefil

Filtering my DataGridView in Master-Detail type form with entity framework

My Problem:
This is my form
I would like to just filter out same ID rows
Barely any code to show pretty much dragged and dropped entity-es and did some customizing.
Toolstrip and datagrid are binded to same source
My Goal:
I would like my form to filter out only the rows with same ID as ID in textbox when I navigate with toolbox buttons
My thoughts so far: Perhaps I can make a query where ID in textbox matches ID in first column and weed out those rows and just display them. But how would that keep the format I have? Comboboxes etc.. some columns have different binding sources, for example column #2, column#3 are have different binding sources as opposed to column#1(to which i'm trying to filter rows) and column#4,5
Edit: I have tried following
nastavniPlanProgramDataGridView.CurrentCell = null;
foreach (DataGridViewRow row in nastavniPlanProgramDataGridView.Rows)
{
if(row.Index!=rowIndex)
{
row.Selected = false;
row.Visible = false;
}
else
{
if(row.Index==rowIndex)
{
row.Selected = true;
row.Visible = true;
}
}
However i keep encountering an error when executing row.Visible=false;
Solved by simply adding the following before executing the above code-snippet in the question.
AllowUserToAddRows = false;

WPF Datagrid CollectionViewSource usage when columns are reordered

I am working on WPF Datagrid where we are customizing the grid to support functionalities like search, filter, column Hiding/Un-Hiding etc,
For Filter and Search we are using CollectionViewSource to get the ICollectionView and on that list we are performing various operations mentioned above.
For a particular Functionality like search, User had reordered the columns and then performed search operation, i am getting the ICollectionView data using the below function:
ICollectionView objDatacollectionview =
CollectionViewSource.GetDefaultView(DataSource.DataGridSrcCollection);
DataSource.DataGridSrcCollection is my ObservableCollection<DataRowView>.
From the objDataCollectionView object, I get the itemArray of each row and search for the text and start highlighting the cell where the text is found, but the problem I am facing is my CollectionViewSource object always returns the DataRow ItemArray in the original order when the Grid is loaded, as it is not considering the Column Reordering, the search is not pointing to the first column, it is actually pointing to the column which was the first column when loaded for the first match text.
The question I had is , is there a way to get the item array value in the correct order on how the columns are re-ordered, if not can I use any other approach with Collectionview so that I can highlight the correct item when search is done.
Below is the sample code i had
below is the sample code
objDatacollectionview = CollectionViewSource.GetDefaultView(DataSource.DataGridSrcCollection)
// Initially get all the DataRowview ItemArray , Here i get all the rows itemarray text as it is
var temp = (from s in objDatacollectionview.OfType<DataRowView>()
select s.Row.ItemArray).ToList();
for (int i = 0; i < temp.Count(); i++)
{
// Now in each item array , i search for the string and will get the list of the strings that match the searchText
var cellitems = temp[i].Where(x => x.ToString().Contains(searchText, StringComparison.OrdinalIgnoreCase)).
Select(x => x).ToList();
//This is to point to the row where there is first occurance of the searched text.This will execute only for the first time
if (cellitems.Count() != 0 && !IsfirstSelectedRowIndex)
{
DataRowView dv = objDatacollectionview.OfType<DataRowView>().ElementAt(i);
objDatacollectionview.MoveCurrentTo(dv);
int cellIndex = temp[i].Select((Value, Index) => new { Value, Index }).Single(p => p.Value.Equals(cellitems[0])).Index;
DataGridCellInfo cellinfo = new DataGridCellInfo(cellitems[0], batchDataGrid.Columns[cellIndex]);
batchDataGrid.CurrentCell = cellinfo;
IsfirstSelectedRowIndex = true;
}
} `
In the above code as i am moving through each row itemArray data i have is the original order, not the re-ordered columns, i can use the index to column mapping, but after this operation i have to support previous search item and next search item, so i am thinking that would impact the performance if i am doing search with column display index every time.
Each DataGridColumn has a DisplayIndex property, which will tell you the current position of the column. This will allow you to determine the ordering.

Adding new column in sencha grid before the last column

Suppose i have a sencha grid which has columns
Name, Email, Address, Phone, City, State, Country
Now out this initially i am only displaying Name, Email, Address and Phone.
I have given the provision to display more columns, the pending ones, City, State and Country.
But the problem in that when ever i add a new column in the grid then it gets appended to the last...in my case suppose i add City then it gets appended after Phone...
But i want Phone to always remain the last column and if any other column is added then it should be prefixed before Phone column.
I am using sencha grid.
Kindly suggest
Use headerCt for this. You can insert a new column to any position.
handler: function(btn) {
var grid = btn.up('gridpanel');
var column = Ext.create('Ext.grid.column.Column', {
text: 'Country',
dataIndex: 'country'
});
grid.headerCt.insert(
grid.columns.length - 1, // that's index column
column);
grid.getView().refresh();
}
Fiddle

Custom Edit control inside a ExtJS Editor grid

Got an issue, and need your advices
I just started writing an editor grid. (I will actually use this grid as a search filter editor, i.e. columns with criteria name, operators and values).
Now, for the value field, I want to have different edit controls for different rows. For instance, when a criteria type is string I want to display a text box, when it's date time, I want a datetime editor.
So the fact is, I need to control the "edit control creation/display" just before editing starts. and it should be different among rows. Unlike the examples I found which are fixed for the columns.
In order to implement this, can you guys please suggest the steps I need to do? I can probably figure out it if one of you can direct me a way.
Thanks and best regards
Actually you can easily accomplish this by dynamically returning different editors and renders depending on the column you're in. In your ColumnModel object you can define something like this below. Note that i'm getting a type property of each record to determine its type. I have an object containing all my different types of editors, and the same for renderers, and then based on the the type i dish out a different editor or renderer for that cell.
editors: { 'default': {xtype:'textfield'},
texttype: {xtype:'textfield'},
numbertype: {xtype:'numberfield'},
combotype: {xtype:'combo'}....... etc. }
getCellEditor: function(colIndex, rowIndex) {
var store = Ext.getCmp('mygrid').getStore();
var field = this.getDataIndex(colIndex);
var rec = store.getAt(rowIndex);
var type = rec.get('type');
if (type in this.editors) {
return this.editors[type];
} else {
return this.editors['default'];
}
},
In the configuration section of your editorgrid, you will need to define your custom editors:
{
xtype: 'editorgrid',
id : 'mygridID',
stripeRows: true,
...
...
,customEditors : {
//configs go here or pre-define the configs prior to this
'columnName1' : new Ext.grid.GridEditor(new Ext.form.Combobox(configObject)),
//configs go here or pre-define the configs prior to this
'columnName7' : new Ext.grid.GridEditor(new Ext.form.CheckBox(configObject))
}
}
use this grid config - in order to select whole rows:
selType: 'rowmodel'

Resources