Winform - Not WPF - ListView Currency and Checkbox with C# - c#

Does anyone know how to add a currency to a specific column in ListView, please?
It is easy with WPF but my project is Win form.
CheckBox
I used this code for checkbox, but it only shows checkbox in the first Column.
I want it on 5th Column
listView1.CheckBoxes = true;
Currency
I tried this but it is not good.
ListViewItem viewItem = new ListViewItem(new string[]
{
"£"+emailDetails.Total+".00"
});

ListView in WinForms is a very different animal than ListView in WPF.
For the currency: add a string property to your emailDetails class that formats the currency as desired. I would recommend you format the value once, when you set the Total amount, and then reuse the formatted value in the getter of the new property.
For the checkbox: the only way to have it in a different column than the first is to do custom drawing and draw the combobox yourself. It is more complicated, as you will need to perceive clicks to change the picture of the box, and store the status of every checkbox somewhere.

Related

How to stop entering the text, when user going out of autoCompleteMode text c#

Iam using AutoCompleteMode to my textbox. It will append the Bank names to my textbox. So when I started typing with the first leter all the Bank names with first lettre will come to dropdownlist to my textbox. Now my question is
If user try to entre the data which is not im my dropdownlist, the user should not able to entre the text. So i want user to entr the existing bank names only.
Iam using AutoCompleteCustomSource to the textbox for dropdown.
try something like:
bool foundSome = false;
foreach (var bankName in col)
{
foundSome = bankName.StartsWith(textBox.text);
}
if (foundSome)
//Do some action
You can write this code in 'Validating' to preform for each char inserted in txtbox.
the best way to achieve your requierement is to use 1 textbox and 1 combobox. They both should point to the same collection.
Textbox will behave in autocomplete mode as you described. Once you type, combobox value will be set to first matching value from your collection. If no value matches - combobox value should be set to null or default data.
Combobox will store only corresponding data subset with no possibility to edit the chosen text.
Validation and data retrieval will be done from Combobox value.
Advantages of this approach:
- With large sets of data it will be easier for user to find what he/she needs.
- Lesser code to check if input value belongs to data set or to force belonging.
- No validation is needed.
Possible shortcomings:
- One more control at form.
- Logic to synchronize textbox's text and combobox collection should be implemented.

How to make a specific Column Uneditable In datagridview?

Using a DataGridView, how can I make a specific column uneditable while the grid view itself has "Allow editing" enabled?
Also, how can I execute an event when the selected index in a ComboBox in the DataGridView has changed? Here, ComboBox is a column type.
Another question is, how can I make the header title aligned to the center? I can't find the appropriate property.
You've got a few questions here.
(1) How can I make a specific column uneditable in DataGridView?
Set the ReadOnly flag on the particular column you want to make uneditable.
dataGridView.Columns["YourColumnName"].ReadOnly = true;
(2) How can I execute an event when the selected index on a ComboBox in the DataGridView changes?
If it's in your DataGridView, it's not a ComboBox; it's a DataGridViewComboBoxColumn. According to MSDN:
Unlike the ComboBox control, the DataGridViewComboBoxCell does not have SelectedIndex and SelectedValue properties. Instead, selecting a value from a drop-down list sets the cell Value property.
This one I'm not familiar with, as I've never tried it myself. It appears you want to subscribe to the EditingControlShowing event and then see if something like this works for you (with a little tweaking).
(3) How can I make the header title align in the center?
Set the HeaderCell.Style.Alignment
dataGridView.Columns["YourColumnName"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

Databind Datagridview Combobox to a numeric field in c#.net 4.0

I am trying to bind a numeric field in an oracle table to a Datagridview - combo list in windows forms. With this what am trying to achieve is;
1 ) Based on the numeric value present in the number field, fetch ad display the respective string value in dataviewgridcombolist column.
2). When a new row is added in the datagrid view, the user may be allowed to select a listed (string) value in the combo list and the respective index value to be stored in the table back.
lots of thanks in advance..
Regards
Rithesh Krishnan
I've created a customized grid control. Where you can specify each column type the respective editing control will be displayed - for the combo box column a combo box field will be displayed, for the numeric column a numeric editor will be displayed.
While user adding a new row also user will get these editors. Usage of this class as follows
customDataGrid1.ColumnDataTypeMapping.Add("EmployeeName", CustomDataGrid.CustomDataGridColumnType.TEXT);
customDataGrid1.ColumnDataTypeMapping.Add("ManagerID", CustomDataGrid.CustomDataGridColumnType.COMBOBOX);
customDataGrid1.ColumnDataTypeMapping.Add("JoinDate", CustomDataGrid.CustomDataGridColumnType.DATE);
customDataGrid1.ColumnDataTypeMapping.Add("DateOfBirth", CustomDataGrid.CustomDataGridColumnType.DATETIME);
customDataGrid1.ColumnDataTypeMapping.Add("Salary", CustomDataGrid.CustomDataGridColumnType.NUMERIC);

Displaying a value in a populated combo box

Here is the situation:
I have populated a combo box with the names of divisions in my company and it is working fine. I go into edit mode and pull one record out of the data table so I bind all controls on the form with one record. I also populate this combo box with all divisions but want it to display the selected division. While I know how to display correct date in textbox controls, I do not know how to make combo box display only selected data. It displays the first record from the query which populates it. Any suggestions?
Thanks
Not clear if you are using ASP.NET or Windows Form. I am assuming Windows Form at the moment since it has an actual ComboBox control, while ASP.NET only has DropDownList (not counting the AJAX Control Toolkit).
ComboBox has a bunch of Selected... properties, i.e. SelectedIndex, SelectedItem, SelectedValue, SelectedText that you can manipulate (set) to show a certain item on the screen. So you can just do cbDivision.SelectedText = myRecord.Division (assuming Division in myRecord contains the same name as the one bound in the ComboBox.
for reference, see: this
I'm not sure I understood your question correctly. But I think you just want to display the selectedValue in the dropdown list populated from a list of values.
< asp:DropDownList DataTextField="SomeDecsription" DataValueField="SomeValue" ...... />
I apologise if this is not what you were asking for

WPF DataGrid with cell style -- different cell style in same column

I was just wondering how can I assign different cell style for same column? Cell style might be combo box or text box.
Image uploaded. Is it really hard?
I want to display a table in data grid. The first column should be name of the table field, second column should be the value of the column.
now if the first column cell data type is var char , then second column cell should display text box.
if the first column cell data type is int, then second column cell should display combo box.
Thanks,
N avatar
You could :
Derive from DataGridBoundColumn (or one of its derivatives) and override the
protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
method. This method creates the item that appears in each cell. The dataItem passed as a parameter is the item in the row. The hassle is that to decide what item you use to display the current cell value you will have to perform the binding manually to get the item to display in the cell and then see what ui control to return.
Use a Template Column and in the cell template use data triggers to swap in the ui element that you wish to display.
When asking this question, keep in mind that there are two different kinds of WPF datagrids. The one released on CodePlex in the WPFToolkit which uses .NET Framework 3.5 SP1. And the newer WPF DataGrid released as a built-in control in WP4 which uses .NET Framework 4.0.
Your solution may differ depending on which datagrid you decide to use, and its possible you may find one to work better than the other.
That being said, I found an article on C# Corner that describes how to display a combobox in a cell when the cell is in edit mode. This may help you. If you start here, you may find that you can extend this code sample to fit your needs. And in the cases where you need to use a textbox instead of a combobox when editing, you could probably set the combobox to allow typing in new values, essentially letting the user type in values in a textbox when the item they want is not available. Not sure if this is what you want, but I at least wanted to give you something to chew on.
Good luck,

Categories