Table cells are not available for editing in FastReport - c#

This issue occurred after update.
Cell without initial value after click not change state, i.e. they look like disable, but when I start fill cell start expanding.
Gif
But if fill cell by initial value, space for example, it's work fine.
Has anyone encountered a similar problem and how did you solve it? Case with a space is not very pleasant.

In the new version of FastReport, the TextRenderType property has been added for text fields. Since the cell is inherited from the text field, then this property is available to it.
Setting the value to HtmlParagraph solves this problem, but when exporting to excel turns some cells into pictures.
If there are many cells and manually changing the value is problematic, you can use the code:
var tableCells =
report.AllObjects.ToArray().Where(item => item.GetType() == typeof(TableCell)).Cast<TableCell>();
foreach (var tableCell in tableCells)
{
tableCell.TextRenderType = TextRenderType.HtmlParagraph;
}
But execute it before the Prepare() method and after loading the document template.

Related

How can you fill a table cell using Selenium?

I'm trying to fill a table using the selenium drivers and all the documentations I could find only shows how to retrieve data from the cells. I'm able to access my table cells using:
var rows = Driver.FindElement(By.Id("Products")).FindElements(By.XPath("id('Products')/tbody/tr"));
var cells = tableRows[1].FindElements(By.XPath("td"));
But I couldn't find any way to update the data that's in it. The "Text" property only has a Get method and the SendKeys() function doesn't work. How can I edit the cell's value?
As a side note, my cell contains an html "input", I've tried to access it with the FindElement function of the cell but for some reasons it cannot find it.
Generally speaking, SendKeys should work if the cell indeed contains the input element. But because you're also saying that you fail to find the input element, I suspect that the input element does not exist in each cell all the time. You should probably first click on the cell in order for the input element to appear on that cell. You should be able to verify it using the Dev Tools if you inspect the element before clicking it.
IWebElement doesn't provide a method to change text, but you could use a little bit of JS - something little like :
((IJavaScriptExecutor)Driver).ExecuteScript("document.getElementByXXXXX.innerHTML = "VALUE";");
https://seleniumhq.github.io/selenium/docs/api/dotnet/html/M_OpenQA_Selenium_IJavaScriptExecutor_ExecuteScript.htm

How does one get rid of this design-time row in the DataGridView row at run-time?

I'm using a DataGridView in a WinForm for the very first time, and have run into an odd problem.
I'm trying to populate the DataGridView control from the database. I'm not binding it to a dataset or anything, but retrieving a set of rows from a Sqlite query. I am then populating the rows programmatically from the data retrieval result. The grid is set up like this (as it appears in the designer):
What happens at runtime is fine, except for what appears to be a "phantom" row, which shows up in the grid as it appears in the designer, as the last row (blank or unpopulated), when I finish loading the grid. I've tried clearing the rows:
DataGridView.Rows.Clear();
But this doesn't clear anything. Trying to remove or make this row invisible fails with an exception because it's apparently uncommitted.
How do I get rid of the thing?
After entering the question in its entirety, I tried one last time to see if there was something that stood out. So I examined the properties of the DataGridView in close detail and wondered about some of the properties whose function I wasn't sure about.
The answer turned out to be the property AllowUserToAddRows. The "uncommitted row", as the exception designated it, is the place where the user would add the information for a new row that is to be inserted! Since this implementation of the grid is intended to be for editing of existing rows only, setting this property to False removed the apparently "bogus" row, and solved my problem.
And incidentally removed the row from the designer.

How to end the DataGridView Cells Edit Mode automatically?

this is a follow up question from my previous one. you can find it here.
I got another problem after finally solving my previous one, when I assign the button to add the value into a new row in DataGrid, the entire cell will be on edit mode, until I clicked on other cell and filled it and/or tabbed till the end of the row (well apparently this one doesn't work), then it will end the edit mode.
I'm using dataGridView.BeginEdit(true); to begin the edit mode so that I could parse a value into the textbox (see my previous question). So, if I insert another value and press the button, the new value will replace the old value that was inserted previously because it is currently still on edit mode.
I was trying to use dataGridView.EndEdit();, dataGridView.EndEdit(DataGridViewDataErrorContexts.Commit);, cell.DataGridView.EndEdit() and cell.DataGridView.EndEdit(DataGridViewDataErrorContexts.Commit); but apparently that doesn't end the edit mode :(
What I wanted is when I press the button, the value inside the textbox will be inserted into the first textbox column (this one already worked). Then I don't have to click or fill the other column to end the edit mode. So, I'll just type anything into the textbox and press the button only until I wanted to stop. After that I begin to fill the other column.
does anyone know how to solve this?
EDIT 1: do you see the difference? look at the red circle, the top one is currently in edit mode (because it has a * after the arrow). the bottom one is not in edit mode (I did it manually by picking an item from the combobox).
Here is my code as requested from my previous question:
private void button1_Click(object sender, EventArgs e)
{
this.surat_jalanDataGridView.AllowUserToAddRows = true;
string tokNum = this.textBox1.Text;
if (this.textBox1.Text != "")
{
foreach (DataGridViewRow sjRow in this.surat_jalanDataGridView.Rows)
{
int RowIndex = surat_jalanDataGridView.RowCount - 1;
DataGridViewRow R = surat_jalanDataGridView.Rows[RowIndex];
DataTable table = new DataTable();
DataRow newRow = table.NewRow();
table.Rows.Add(newRow);
DataGridViewCell cell = R.Cells[2];
this.surat_jalanDataGridView.CurrentCell = cell;
this.surat_jalanDataGridView.BeginEdit(true);
R.Cells[2].Value = tokNum;
cell.DataGridView.EndEdit(DataGridViewDataErrorContexts.Commit);
}
}
this.surat_jalanDataGridView.EndEdit(DataGridViewDataErrorContexts.Commit);
}
EDIT 2: So, I drag and drop the surat_jalan from the data sources into my windows form. then it automatically become a datagrid with the property name surat_jalanDataGridView and the data source is surat_jalanBindingSource
Sorry about the delay. After seeing how you set up your binding to your DataGridView I can definately give you better guidance on how to edit the data that the grid is bound to. When you dragged the table from the data sources view in Visual Studio and dropped it on the DataGridView, Visual Studio did several things for you. It is important that you at least understand the basics of what was done so that you understand how you can manipulate you data moving forward. This
MSDN article how to setup binding to windows forms controls from Visual Studio. The last section describes what you are doing. The last sentences "The DataGridView control is now bound to the table that you have dragged onto it. A DataSet, TableAdapter, and BindingSource appear in the component tray." are the important ones. Since Visual Studio generated code that bound your control to your table you should edit the data directly to update your data grid view. In this case you should work with the generated DataSet (I'm assuming it was named surat_jalanDataSet). Here is a description of how to edit data in a DataSet. For your specific case Adding Rows. Please let me know if this helps you acheive your goals.
My work around to force a Cell out of EditMode is to toggle the CurrentCell.ReadOnly property.
this.dataGridView.EndEdit();
this.dataGridView.CurrentCell.ReadOnly = !dataGridView.CurrentCell.ReadOnly;
this.dataGridView.CurrentCell.ReadOnly = !dataGridView.CurrentCell.ReadOnly;
Similar technique works with other components that do not have explicit and functional EndEdit or Commit type methods.
For example, you can end the DateTimePicker's text edit mode by toggling its dateTimePicker.Enabled property.
//AJ

C# Datagridview: Combobox Column cell value is null even after user selects item

I'm constructing a GUI that allows the user to manipulate XML data. A helpful fellow named Peter was able to point me to a direction leading me to question why my cell values were null even when the user selects a value in the combobox.
I've read up on a few things: the comboboxcolumn's value member, display member, data source, and datapropertyname. I've figured out what display and value members do, but decided to stick with a data source so I wouldn't have to specify a display member and value member; I believe it made things easier and plus the choices in the combobox are stored in a string array.
The premise is, the user enters in choices into a rich text box. Then, the textbox is read line by line and every line becomes a choice in the combo box. I then create a new combobox column in the datagridview and the choices are available for the user to choose. After the user is done, I have a button called "save with combo column..." which creates a new datacolumn in the datatable that the datagridview is displaying and I try to copy the values over via this code: (since I cannot directly merge the combobox column with a datatable)
int size = dataGridView1.Rows.Count - 1;
DataColumn column = new DataColumn(combo.HeaderText);
data_set_array[(int)IndexNumber.Value].Tables[(int)TableNumber.Value].Columns.Add(column);
for (q = 0; q < size; q++)
{
data_set_array[(int)IndexNumber.Value].Tables[(int)TableNumber.Value].Rows[q][combo.HeaderText] = dataGridView1["combo", q].Value;
}
when that is all said and done, the new column is created and a message is displayed. However, the datatable's values are null, which means the cell values are also null. This implies that the item that the user selected in the combo box wasn't copied over to the cell value. What am I doing wrong? I set the datasource to the string of arrays where the strings are the user's choices for the combobox, and yet when the I selected choices from the combobox and tried to save it, the values are null. I also read that I did not need to worry about value member or display member since setting the datasource would provide me valid display text and valid values.
If any additional information is needed please ask. Thanks in advance.
.NET 3.5 SP1, Visual Studio 2008 C#.
Sincerely,
tf.rz
I am not sure
However I think you will find that the datarows have been created using the old column definitions.
when you add a new column i doubt it is resizing the arrays for each row to add a column.
Although if this was true i would expect an index out of range exceptions.
you need to break that big line of code up so so that it is easier to debug.
IE when you leave the loop does the cell have the value you expect? Or has the assign failed?
It will tell you where things are going wrong.
If it is assigning then you lose the data later then you need to expand your search (this could happen if you have somehow assumed a value type was a reference type for instance)
you may finid you need to create a new data table with the correct column definitions and then copy the old data into the new one ... but first you need to establish where it is failing - you are currently doing too much in 1 line of code.
Are you sure the value syou are getting from the combo box are not null?

Editing DataGridView cells without a bound source?

New to .NET/C# stuff so please forgive me if it's something obvious ;-) I'm trying to get cell editing going on a DataGridView control (WinForms). I've set all "ReadOnly"-type options to false, I've set EditMode to "EditOnEnter", I've added a row and selected a current cell programmatically, I've tried calling BeginEdit() but all to no avail - I can't edit the cell's contents.
The only thing that I can think of is that the control isn't bound to a data source - I'd like to be able to use it in a spreadsheet manner, so as the contents are typed in, I can then add new rows etc, and on a button click, the data can be retrieved programmatically for later use.
Is this possible?
Thanks,
Rich
I do that all the time (i.e. allowing users to edit a column without the DataGridView being bound).
Try this:
Set EditMode to EditOnKeystrokeOrF2
Ensure ReadOnly on the DataGridView is set to false
Ensure that ReadOnly on the column you want to edit is set to false
That should work.

Categories

Resources