I'am having simple problem with DevExpress LookUpEdit DisplayFormat. I want to achieve results in lookUpEdit like:
Document type (.doc)
Document type (.docx)
const string defaultExtensionsList = "doc;docx;xlsx;xls;pdf;txt";
//...
var column = new LookUpColumnInfo("Column", "Extensions")
{
Visible = true,
//FormatType = FormatType.Custom,
//FormatString ="Document type (*.{0})",
Alignment = HorzAlignment.Near
};
ExtensionsLookup.Properties.DisplayFormat.FormatType = FormatType.Custom;
ExtensionsLookup.Properties.DisplayFormat.FormatString = "Document type (*.{0})";
ExtensionsLookup.Properties.EditFormat.FormatType = FormatType.Custom;
ExtensionsLookup.Properties.EditFormat.FormatString = "Document type (*.{0})";
ExtensionsLookup.Properties.Columns.Add(column);
var bindingList = defaultExtensionsList.Split(';').ToList();
ExtensionsLookup.Properties.DataSource = bindingList;
You can use the following trick (RepositoryItemLookUpEdit.GetNotInListValue event):
const string defaultExtensionsList = "doc;docx;xlsx;xls;pdf;txt";
//...
var columnID = new LookUpColumnInfo("Column", "IDs") { Visible = false };
var columnToDisplay = new LookUpColumnInfo("Display", "Extensions");
lookUpEdit.Properties.Columns.AddRange(new LookUpColumnInfo[] { columnID, columnToDisplay });
lookUpEdit.Properties.ValueMember = "Column";
lookUpEdit.Properties.DisplayMember = "Display";
lookUpEdit.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
lookUpEdit.Properties.GetNotInListValue += OnGetNotInListValue;
var bindingList = defaultExtensionsList.Split(';').ToList();
lookUpEdit.Properties.DataSource = bindingList;
//...
void OnGetNotInListValue(object sender, GetNotInListValueEventArgs e) {
if(e.FieldName == "Display")
e.Value = string.Format("Document type (*.{0})",
((IList<string>)lookUpEdit.Properties.DataSource)[e.RecordIndex]);
}
If I remember correctly, LookUpEdit doesn't support this functionality.
I would simply build a List with values "Document type (.docx)", "Documentype (.xy)" and bind it to the control.
Something like
var types = defaultExtensionsList.Split(';').Select(s => "DocumentType (*." + s + ")").ToList();
Related
I have section in my class that looks like this:
public Details GetTicketById(string #ref)
{
var query = "SELECT * FROM support WHERE ref = #ref";
var args = new Dictionary<string, object>
{
{"#ref", #ref}
};
DataTable dt = ExecuteRead(query, args);
if (dt == null || dt.Rows.Count == 0)
{
return null;
}
var details = new Details
{
#ref = Convert.ToString(dt.Rows[0]["ref"]),
subject = Convert.ToString(dt.Rows[0]["subject"]),
contact_name = Convert.ToString(dt.Rows[0]["contact_name"]),
company_name = Convert.ToString(dt.Rows[0]["company_name"]),
description = Convert.ToString(dt.Rows[0]["description"]),
business_impact = Convert.ToString(dt.Rows[0]["business_impact"]),
severity = Convert.ToString(dt.Rows[0]["severity"])
};
return details;
}
I know that there is a return value when I debug.
My button in my main form looks like this:
private void Button3_Click(object sender, EventArgs e)
{
var getTicket = new ticket();
getTicket.GetTicketById("1235");
ticket.Details td = new ticket.Details();
td.#ref = txtRef.Text;
td.subject = txtSubject.Text;
td.contact_name = txtContact_Name.Text;
td.company_name = txtCompany_Name.Text;
td.description = rtDescription.Text;
td.business_impact = rtBusiness_Impact.Text;
td.severity = txtSeverity.Text;
}
Unfortunately my text boxes do not show the values from my returned data table.
Can you see why?
Your method GetTicketById() return value like you and see with debug. But you don't take this value into variable. Do this:
var details = getTicket.GetTicketById("1235");
In order to set Text property to new value do this:
txtSubject.Text = details.subject
txtContact_Name.Text = details.contact_name
txtCompany_Name.Text = details.company_name
// and so on
This line need to delete
ticket.Details td = new ticket.Details();
I'm making a generic converter which reads any file you throw in it which "maps" it's data and gives it like this:
I got 3 classes:
DataValue, which has a value, row, and column property.
DataArray, which is a list of DataValues.
DataArrayList, which is a list of DataArrays.
I try to use put it in a datagrid with non pre-setup columns, since it should be able to read Anything.
Here's some code:
public void FillRows(DataArrayList arrayList)
{
DataArray headers = arrayList.First();
AddColumns(headers);
DataList = new List<DataArray>();
lijstitems = new List<DataValue>();
foreach (DataArray dataArrays in arrayList)
{
DataList.Add(new DataArray { datavalues = dataArrays.datavalues });
}
DataContext = this;
}
Now this gives me the general name of the arrays, as a test i tried to display it in textboxes. Now i wonder how i would get a setup which displays each DataValue as a new column.
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
DataArray array = (DataArray)DataGrid.SelectedItem;
var arraychar = array.datavalues.ToArray();
textBox1.Text = arraychar[0].value.ToString();
textBox2.Text = arraychar[1].value.ToString();
textBox3.Text = arraychar[2].value.ToString();
textBox4.Text = arraychar[3].value.ToString();
textBox5.Text = arraychar[4].value.ToString();
}
This displays the correct values i put in.
Define a column per value you want to display in the DataGrid:
DataGrid.AutoGenerateColumns = false;
DataGrid.Columns.Add(new DataGridTextColumn() { Binding = new Binding("[0]") });
DataGrid.Columns.Add(new DataGridTextColumn() { Binding = new Binding("[1]") });
DataGrid.Columns.Add(new DataGridTextColumn() { Binding = new Binding("[2]") });
DataGrid.Columns.Add(new DataGridTextColumn() { Binding = new Binding("[3]") });
DataGrid.Columns.Add(new DataGridTextColumn() { Binding = new Binding("[4]") });
I'm using gridControl.DataSource from WCF Service and add manual RepositoryItemComboBox to gridControl. but RepositoryItemComboBox cannot show combo-box list data.
this my code :
gridControl8.DataSource = service.jadwalUmumStaff(data).Select(r => new
{
hari = r.jadwal_umum.hari,
shift = r.jadwal_umum.fk_jadwalUmum_Shift.id_shift,
waktu = r.jadwal_umum.fk_jadwalUmum_Shift.waktu,
mata_kuliah = r.jadwal_umum.fk_jadwalUmum_matakuliah.mata_kuliah,
nama = r.staff.nama,
} ).ToList();
RepositoryItemComboBox nama = new RepositoryItemComboBox()
{
TextEditStyle = TextEditStyles.DisableTextEditor,
ShowDropDown = ShowDropDown.SingleClick
};
var a = service.getStaffID();
string[] _a = new string[a.Count()];
for (int i = 0; i < a.Count(); i++)
{
_a[i] = a[i].id_staff;
}
nama.Items.AddRange(_a);
gridControl8.RepositoryItems.Add(nama);
gridView8.Columns[4].ColumnEdit = nama;
gridControl8.ForceInitialize();
you need AllowDropDownWhenReadOnly and set value true
following this code :
RepositoryItemComboBox nama = new RepositoryItemComboBox()
{
TextEditStyle = TextEditStyles.DisableTextEditor,
AllowDropDownWhenReadOnly = DevExpress.Utils.DefaultBoolean.True
};
I've got a class with two public properties, Name and Text. I want to bind a DataGridView to a list of these objects, so I loaded them into a BindingList<>. I only want to show the Name property in the DataGridView, but I'm getting both columns. What am I doing wrong?
private void fileOpenTextBox1_FileSelected(object sender, string e)
{
m_definitions = new BindingList<TagSimDefinition>(TagSimDefinition.Read(e));
dgvTagNames.AutoGenerateColumns = false;
dgvTagNames.Columns.Clear();
DataGridViewCell cell = new DataGridViewTextBoxCell();
DataGridViewTextBoxColumn colTagName = new DataGridViewTextBoxColumn()
{
CellTemplate = cell,
Name = "colTagName",
HeaderText = "Tag Name",
DataPropertyName = "Name"
};
dgvTagNames.Columns.Add(colTagName);
dgvTagNames.DataSource = m_definitions;
}
#Robert you are setting,
dgvTagNames.DataSource = m_definitions;
for that it is showing both columns. If you want to get one column use it like this,
m_definitions = new BindingList<TagSimDefinition>(TagSimDefinition.Read(e));
dgvTagNames.AutoGenerateColumns = false;
dgvTagNames.Columns.Clear();
dgvTagNames.ColumnCount = 1;
dgvTagNames.Columns[0].Name = "colTagName";
dgvTagNames.Columns[0].DataPropertyName = "colTagName";
dgvTagNames.DataSource = m_definitions;
Another solution:
m_definitions = new BindingList<TagSimDefinition>(TagSimDefinition.Read(e));
dgvTagNames.Columns.Clear();
DataGridViewCell cell = new DataGridViewTextBoxCell();
DataGridViewTextBoxColumn colTagName = new DataGridViewTextBoxColumn()
{
CellTemplate = cell,
Name = "colTagName",
HeaderText = "Tag Name",
DataPropertyName = "Name"
};
dgvTagNames.Columns.Add(colTagName);
dgvRegion.Rows.Clear();
int index = 0;
foreach (var dparam in m_definitions)
{
dgvTagNames.Rows.Add();
dgvTagNames["colTagName", index].Value = dparam.<Property1>;
dgvTagNames.Rows[index].Tag = dparam;
index++;
}
Everyone here is making things wayyyyyyy to complicated. If you have columns you don't want displayed you could just set the Column.Visible = false after the setting the datasource.
dgvTagNames.Columns[index].Visible = false;
I have a TextBox, in which I put a phrase, which is either the description of a task or the id of a task. I want to filter a list using the text from this TextBox. But when I put text into this TextBox, filtering doesn't work, and the collection in the DataGridView doesn't change.
What can be wrong?
public void BindData()
{
var emptyBindingSource = new BindingSource();
dataGridViewTaskList.AutoGenerateColumns = false;
dataGridViewTaskList.DataSource = emptyBindingSource;
var taskList = GetTasks();
_bindingSource = new BindingSource();
_bindingSource.DataSource=taskList.Response;
dataGridViewTaskList.AutoGenerateColumns = false;
dataGridViewTaskList.DataSource = _bindingSource.DataSource;
if (dataGridViewTaskList.Columns["gridViewColumnId"] == null)
dataGridViewTaskList.Columns.Add(new DataGridViewColumn() {Name = "gridViewColumnId"});
else
dataGridViewTaskList.Columns["gridViewColumnId"].DataPropertyName = "Id";
if (dataGridViewTaskList.Columns["gridViewColumnDescription"] == null)
dataGridViewTaskList.Columns.Add(new DataGridViewColumn() {Name = "gridViewColumnDescription"});
else
dataGridViewTaskList.Columns["gridViewColumnDescription"].DataPropertyName = "Description";
}
private void tbSearchedPhraseOrId_TextChanged(object sender, EventArgs e)
{
_bindingSource.Filter = string.Format("Id = '{0}'", tbSearchedPhraseOrId.Text);
}
I added the following in BindData method and it doesn't work either:
_bindingSource.Filter = string.Format("Id LIKE '%{0}%'", "23");
Designer:
this.dataGridViewTaskList.AllowUserToAddRows = false;
this.dataGridViewTaskList.AllowUserToDeleteRows = false;
this.dataGridViewTaskList.AllowUserToOrderColumns = true;
this.dataGridViewTaskList.AllowUserToResizeRows = false;
this.dataGridViewTaskList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridViewTaskList.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridViewTaskList.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.dataGridViewTaskList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridViewTaskList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.gridViewColumnId,
this.gridViewColumnDescription});
this.dataGridViewTaskList.Location = new System.Drawing.Point(6, 62);
this.dataGridViewTaskList.MultiSelect = false;
this.dataGridViewTaskList.Name = "dataGridViewTaskList";
this.dataGridViewTaskList.ReadOnly = true;
this.dataGridViewTaskList.RowHeadersVisible = false;
this.dataGridViewTaskList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridViewTaskList.Size = new System.Drawing.Size(414, 488);
this.dataGridViewTaskList.TabIndex = 0;
According to the documentation, your underlying data source (i.e. your task list) must implement the IBindingListView interface to have a working Filter property. Are you sure this is the case right now?
(As an aside, you should set the DataSource property of your DataGridView to the BindingSource object itself rather than the BindingSource.DataSource property.)
You can always check _bindingSource.SupportsFiltering
to see if the BindingSource type supports filtering
You should change:
dataGridViewTaskList.DataSource = _bindingSource.DataSource;
to
dataGridViewTaskList.DataSource = _bindingSource;
By changing _bindingSource.Filter you're not actualy changing _bindingSource.DataSource - it stays the same and because of that dataGridViewTaskList.DataSource doesn't change either. In the other hand, _bindingSource is changed, and you can bind directly to it to get that change.
Did you try with:
_bindingSource.Filter = string.Format("gridViewColumnId = '{0}'", tbSearchedPhraseOrId.Text);
Can you define taskList structure?
Try to call : _bindingSource.ResetBindings(false); after setting filter.
Also you can try to call:
dataGridViewTaskList.ResetBindings();
dataGridViewTaskList.Refresh();
dataGridViewTaskList.Update();
Alternative
IEnumerable, List.....etc Global Variable
listBindingSource.DataSource = List();
Then simple filter the list and Re-assign it
listBindingSource.DataSource = List.FindAll(t => t.x == yourValue);