 |
|
 |
Hello, thanks for this very good Control. In only less than 200 lines of Code... Very good. Thank you. I use your control to show different Lists in each Row, so i have no "overall"-datasource, but a datasource for each cell. If i do that, i don't get the selected items value as cellvalue but instead i get "System.Data.DataRowView". I have no idea what is going wrong here. I changed my source to have an column-datasource and different datasources for each cell. But the result is the same. Do you have any idea? Help would be appreciated! Thank you! Stefan
|
|
|
|
 |
|
 |
Hi, Stefan.
I am not sure I understood.
Can you send me some code snippet to give me indication?
By the way, may be possible that you need to use PropertyGrid control?
Thanks
Issahar
|
|
|
|
 |
|
 |
Hello Issahar, thanks for your reply. For Example i have the query-result of "Select InvoiceNo, InvoiceDate from Invoices" as datasource of the column, and the first row has the query-result of "Select InvoiceNo, InvoiceDate from Invoices where InoiceCustomer = 123' So, each Cells datasource is a subset of the datasource of the column. Many Thanks for your help! Stefan
|
|
|
|
 |
|
 |
I didn't do the whole way(it is failing some times), but it is the direction you can continue:
using my demo:
1. in frmDemo.cs, change all the data sources to point the same table
newColumn.CellTemplate = new DataGridViewMultiColumnComboCell();
newColumn.DataSource = ds.LogTable; newColumn.HeaderText = ds.LogTable.TypeColumn.ColumnName;
newColumn.DataPropertyName = ds.LogTable.TypeColumn.ColumnName;
newColumn.DisplayMember = ds.LogTable.TypeColumn.ColumnName; newColumn.ValueMember = ds.LogTable.TypeColumn.ColumnName; newColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
2. Create table on the fly
public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
DataGridViewMultiColumnComboEditingControl ctrl = DataGridView.EditingControl as DataGridViewMultiColumnComboEditingControl;
ctrl.ownerCell = this;
SampleDBDataSet ds = DataGridView.DataSource as SampleDBDataSet;
SampleDBDataSet.LogTableDataTable tempTable = new SampleDBDataSet.LogTableDataTable();
DataRow[] rows = (DataSource as DataTable).Select(string.Format("[{0}]={1}", ValueMember, Value));
foreach (DataRow row in rows)
{
SampleDBDataSet.LogTableRow rowNew = tempTable.NewLogTableRow();
foreach (DataColumn col in tempTable.Columns)
{
rowNew[col.ColumnName] = row[col.ColumnName];
}
tempTable.AddLogTableRow(rowNew);
}
ctrl.DataSource = tempTable;
}
There is some problem when after combob value selection changes, try to solve it.
Issahar
|
|
|
|
 |
|
 |
Thanks for the great article, I am using it as the basis for my own extended DGVmulticolumn combo box. The thing I am having trouble with now is AutoComplete, when I use Suggest or SuggestAppend I want the columns to be displayed in the drop-down list. Any ideas on what event/message I need to trap in order to draw my own drop-down displaying the columns in Suggest mode?
|
|
|
|
 |
|
 |
Hi, Linoli!
I invested some time to check possible solution for you. I took the Managed Spy++ and checked if there is some event shut during the autocomplete control opens and I didn't see any . It seems like you wil need to implement your own functionality and not using standart autocomplete feature. You can analyze the text changing events on the compbobox and display the dropdown of yours implementing custom draw as it is done in multicolumn combobox. Definitely needs coding.
Issahar
|
|
|
|
 |
|
 |
Hello, I managed to populate the combobox, but I can not see the value in the cell, it appears empty.
I've set. ValueMember and. DisplayMember as in your code, but the cell is empty
I Must set other property?
I am Newbie
Thanks
|
|
|
|
 |
|
|
 |
|
 |
Sir,
I like the control, i have a question how can i modify the columns width per column. example column1=100 and column2=50
Thank you very much.
|
|
|
|
 |
|
|
 |
|
 |
Is there a way for popular manually the comboboxmulticolumn, adding the columns?
|
|
|
|
 |
|
 |
You can may be do the trick by adding columns to the datasource table. (these columns may not exist in the table itself but you can dynamically add them by relevant code)
e.g. in my implementation, add more columns to ds.LogMessageTypes table and you will see them in the drop down list.
Hope it helps
Issahar
|
|
|
|
 |
|
 |
Thanks for the answer. I have tried to popular the combo with databinding without succeeding the datagridview is polulated regularly
You can help me to improve the code?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PopulateBindingList()
PopolaBindingListDatagrid()
DataGridView1.DataSource = pColonneData 'popola datagridview
'create the multicolumncombo column
Dim newColumn As New DataGridViewMultiColumnComboColumn()
newColumn.CellTemplate = New DataGridViewMultiColumnComboCell()
newColumn.DataSource = moEmployeeBindingList 'popola comboboxmulticolumn
newColumn.HeaderText = "Partite"
newColumn.Width = 150
DataGridView1.Columns.Insert(1, newColumn)
End Sub
thanks for the attention
|
|
|
|
 |
|
 |
Hi, Sergio.
Please see the sample code inside the article...
The rows
newColumn.DataSource = ds.LogMessageTypes;
newColumn.DisplayMember = ds.LogMessageTypes.TypeNameColumn.ColumnName;
newColumn.ValueMember = ds.LogMessageTypes.TypeIdColumn.ColumnName;
should make the data source binding for you
Additionally, before you set the data binding, add columns to ds.LogMessageTypes table and you will see them inside the combobox.
Issahar
|
|
|
|
 |
|
 |
Is there a way to use as a combobox not in a datagrtidview?
Thanks
|
|
|
|
 |
|
 |
Penso que e possibile...
Following is theoretical description, I didn't write such code but I suppose it will work for you:
The standard combobox has owner draw option
DrawMode = OwnerDrawFixed (or dynamic), I don't remember now
After that you leaten for the DrawItem event and make similar code as I did in my implementation
Grazie
Issahar
|
|
|
|
 |
|
 |
I'm not able to customize your good works, I'm an applicant.
I was trying to manage different column width.
Have you any suggestion?
Thanks in advance
Regards
Andrea
|
|
|
|
 |
|
 |
Hi, Andrea!
Do you mean the grid column width or ownwer draw combobox width?
If you mean the combo ones, It will require some coding - you will need to change the logic of the DrawItem event.
Actually, it works in dynamic way, so, before loading the data, combobox doesn't know how exactly columns it has.
There is a following part in my code:
const int fixedAlignColumnSize = 100;
So, if I am not wrong (i wrote this code long long time ago), in current stage, the column size is the same for all the columns.
What you possibly need to do is to create some collection of column sizes here and check every column size value in this collection..
e.g. in every
foreach (object dataRowItem in row.ItemArray)
iteration, get the fixedAlignColumnSize value from collection and not like current constant value
I hope it will give you direction
Thanks
Issahar
|
|
|
|
 |
|
 |
Thanks Issahar for your replay.
I solved, adding a property to the column
public class DataGridViewMultiColumnComboColumn : DataGridViewComboBoxColumn
{
private int _ColumnWidthDefault = 75;
private string _ColumnWidthString = "";
public string ColumnWidths
{
get
{
return _ColumnWidthString;
}
set
{
_ColumnWidthString = value;
}
}
public DataGridViewMultiColumnComboColumn()
{
//Set the type used in the DataGridView
this.CellTemplate = new DataGridViewMultiColumnComboCell();
}
}
and then modifyng the currentoffset update in the ondraw method
char[] delimiterChars = { ',', ';', ':' };
string[] STRcolWidths = column.ColumnWidths.Split(delimiterChars);
STRcolWidths = column.ColumnWidths.Split(delimiterChars);
int temp_col_offset;
int.TryParse(STRcolWidths[temp_col_num], out temp_col_offset);
currentOffset += temp_col_offset;//fixedAlignColumnSize;
temp_col_num += 1;
don't worry regard my c# coding technich, I'm an applicant every suggest will be appreciated.
Now,can you guide me to make the combo drawing the list in different width regard the dbgrid column width ( I would like to show the list items larger than the dbgrid column)
Thanks
|
|
|
|
 |
|
 |
Hi!
I don't think that in current implementation scope, you can do the combo drop down list width bigger than the grid cell width.
The reason seems me because the combobox is automatically anchored to the cell size.
May be there is some workaround but in current stage I don't have good ideas
Issahar
|
|
|
|
 |
|
 |
Dear Mr. Issahar,
I tried to do something like this in my project but i fail. Can i use yours? and can u be so kind and give me a quick tutorial of how can i implement your feature into my application (witch is C# Windows Forms)
P.S. I'm a beginner into c#
|
|
|
|
 |
|
 |
Thanks for good words.
Yes, feel free to use this for any purpose including commercial one.
Regarding the tutorial, I think this site have good ones about every topic.
May be try to search tutorial movies, it is very effective in learning...
I am not very strong in tutorials
Issahar
|
|
|
|
 |
|
 |
Great work! Can I use this in another article?
|
|
|
|
 |
|
 |
You are welcome to use it in your article.
Issahar
|
|
|
|
 |
|
 |
How can i use this with auto complete feature..
Regards
Naveen
|
|
|
|
 |