QTableWidget set column and get column - qt

I'm trying to set programmatically some values of my QTableWidget, but it seems not working.
In my primary thread, I set the table with (PRIMARY_SET):
Status="N";
Number = QString::number(x);
Name= "abc;
nrow=i;
QTableWidgetItem *item_Number = new QTableWidgetItem(Number);
QTableWidgetItem *item_Name = new QTableWidgetItem(Name);
QTableWidgetItem *item_Status = new QTableWidgetItem(Status);
QTableWidgetItem *icon_item = new QTableWidgetItem;
QIcon icon("path/to/.png");
icon_item->setIcon(icon);
ui->TabKeyAlarm_TableED->setItem(nrow, 0, item_Number);
ui->TabKeyAlarm_TableED->repaint();
ui->TabKeyAlarm->repaint();
ui->centralWidget->repaint();
ui->TabKeyAlarm_TableED->setItem(nrow, 1, icon_item);
ui->TabKeyAlarm_TableED->repaint();
ui->TabKeyAlarm->repaint();
ui->centralWidget->repaint();
ui->TabKeyAlarm_TableED->setItem(nrow, 2, item_Name);
ui->TabKeyAlarm->repaint();
ui->centralWidget->repaint();
ui->TabKeyAlarm_TableED->setItem(nrow, 3, item_Status);
ui->TabKeyAlarm_TableED->repaint();
ui->TabKeyAlarm->repaint();
ui->centralWidget->repaint();
for n row and it works.
What I have to do after that is to change the icon and the "Status" on particular row if an event happens.
This is my controll in a separated thread, which do not works (CHECK):
QTableWidgetItem *_getItem = ui->TabKeyAlarm_TableED->item(n_MOD,3);
if (_getItem)
if (_getItem->text() != "K")
{
QEvent(QEvent::Type(QEvent::User+5)));
}
It continuosly call the User+5 event. How can I check if _getItem in row n_MOD and column 3 has already "K" text set ? The result is always _getItem->text() "no such value"...
Then, this is the code for User+5 event (SECOND_SET):
QString _Status_check="";
Status="K";
QTableWidgetItem *icon_item = new QTableWidgetItem;
QTableWidgetItem *item_Status = new QTableWidgetItem(Status);
while (_Status_check != "K")
{
QIcon icon("path/to/.png");
icon_item->setIcon(icon);
ui->TabKeyAlarm_TableED->setItem(n_MOD, 1, icon_item);
ui->TabKeyAlarm_TableED->setItem(n_MOD, 3, item_Status);
_Status_check = ui->TabKeyAlarm_TableED->item(n_MOD,3)->text();
I have to use that "while", because otherwise most of the times _Status_check confirm me that the text in row n_MOD column 3 has still the old text...
So my questions are :
1) In CHECK section, how can I check if the element has already the value "K" ?
2) In SECOND_SET section, why it seems that it takes more than one attempt to set the value in row,column?

Related

DataGrid gets the value of a row and column

I want to get the value of a certain cell in the DataGrid of syncfusion.
like this:
<dataGrid:SfDataGrid x:Name="sfDataGrid">
</dataGrid:SfDataGrid>
C#:
Sfdatagrid\[i,j\] is useless.
How do I get the value of this cell.
https://help.syncfusion.com/winui/datagrid/overview The document
In this official document, I didn't find out how to get the value of this cell according to the index of rows and columns.
I want to get the value of this cell according to the index of the row and column.
Column A
Column B
Cell 1
Cell 2
Cell 3
Cell 4
For example, I want to get the value of this cell according to the index of the row and column.
How should I write code in c#
Your requirement to get the value of this cell according to the index of the row and column in SfDataGrid can be achieved by using View.GetPropertyAccessProvider.GetValue method in SfDatGrid. Please refer the below code snippet,
private void OnGetCellValueClicked(object sender, RoutedEventArgs e)
{
// Get the cell value for RowIndex = 5 and ColumnIndex = 2
int rowIndex = 5;
int columnIndex = dataGrid.ResolveToGridVisibleColumnIndex(2);
object record = null;
if (columnIndex < 0)
return;
var provider = this.dataGrid.View.GetPropertyAccessProvider();
var mappingName = dataGrid.Columns[columnIndex].MappingName;
var recordIndex = this.dataGrid.ResolveToRecordIndex(rowIndex);
if (this.dataGrid.View.TopLevelGroup != null)
{
var displayElement = this.dataGrid.View.TopLevelGroup.DisplayElements[recordIndex];
if (displayElement == null)
return;
if (displayElement is RecordEntry)
record = ((RecordEntry)displayElement).Data;
}
else
{
record = this.dataGrid.View.Records[recordIndex].Data;
if (record == null)
return;
}
var cellValue = provider.GetValue(record, mappingName);
//here display the cell value for RowIndex = 5 and ColumnIndex = 2
if (cellValue != null)
txtGetCellValue.Text = cellValue.ToString();
}

put 2 radiobuttons in one column without overlapping JavaFX

I wanted to ask for help with one problem. I want to move two radio button in one column so that they will both take only as much space as textbox above them. How can I do this? Here is the code and screenshot of current improper version:
Please do not flag my question as duplicate if you are not 100% sure, ok? It is not nice to have your question flag as duplicate of other question, go to this other one and finds out that only common thing is that they are both about programming.
GridPane formGrid = new GridPane();
formGrid.setPadding(new Insets(5,5,5,5));
formGrid.setVgap(6);
formGrid.setHgap(4);
//first row
Label nameLabel = new Label("Name");
GridPane.setConstraints(nameLabel, 0, 0);
TextField nameInput = new TextField();
GridPane.setConstraints(nameInput, 1, 0);
Label ageLabel = new Label("Age");
GridPane.setConstraints(ageLabel, 2, 0);
TextField ageInput = new TextField();
GridPane.setConstraints(ageInput, 3, 0);
//secondRow
Label colourLabel = new Label("Colour");
GridPane.setConstraints(colourLabel, 0, 1);
TextField colourInput = new TextField();
GridPane.setConstraints(colourInput, 1, 1);
Label genderLabel = new Label("Gender");
GridPane.setConstraints(genderLabel, 2, 1);
ToggleGroup pickGender = new ToggleGroup();
RadioButton pickMale = new RadioButton("Male");
pickMale.setToggleGroup(pickGender);
pickMale.setSelected(true);
GridPane.setConstraints(pickMale, 3, 1, 1, 1);
RadioButton pickFemale = new RadioButton("Female");
pickFemale.setToggleGroup(pickGender);
GridPane.setConstraints(pickFemale, 4, 1, 1, 1);
//third row
Label typeLabel = new Label("Type");
GridPane.setConstraints(typeLabel, 0, 2);
//combobox
ComboBox<String> typeBox = new ComboBox<>();
GridPane.setConstraints(typeBox, 1, 2);
Label breedLabel = new Label("Breed");
GridPane.setConstraints(breedLabel, 2, 2);
TextField breedInput = new TextField();
GridPane.setConstraints(breedInput, 3, 2);
//fourth row
Label categoryLabel = new Label("Category: ");
GridPane.setConstraints(categoryLabel, 0, 3);
ToggleGroup pickCategory = new ToggleGroup();
RadioButton pickLost = new RadioButton("Lost");
pickLost.setToggleGroup(pickCategory);
pickLost.setSelected(true);
GridPane.setConstraints(pickLost, 1, 3);
RadioButton pickFound = new RadioButton("Found");
pickLost.setToggleGroup(pickCategory);
GridPane.setConstraints(pickFound, 2, 3);
RadioButton pickAdoption = new RadioButton("Adoption");
pickLost.setToggleGroup(pickCategory);
GridPane.setConstraints(pickAdoption, 3, 3);
//fifth row
Label descriptionLabel = new Label("Description");
GridPane.setConstraints(descriptionLabel, 0, 4);
TextArea descriptionInput = new TextArea();
GridPane.setConstraints(descriptionInput, 1, 4, 2, 1);
formGrid.getChildren().addAll(nameLabel, nameInput, ageLabel, ageInput);
formGrid.getChildren().addAll(colourLabel, colourInput, genderLabel, pickMale, pickFemale);
formGrid.getChildren().addAll(typeLabel, typeBox, breedLabel, breedInput, categoryLabel);
formGrid.getChildren().addAll(pickLost, pickFound, pickAdoption, descriptionLabel, descriptionInput);
Think of it the other way around. The "Female" radio button is in column 4, and so it is to the right of anything in column 3. Column 3 is being forced to be wide enough to hold the two text fields, which is what is forcing that radio button so far to the right. If you want the text fields to span the same horizontal space as the two radio buttons, let them use both the columns the radio buttons occupy: i.e. let the text fields span columns 3 and 4.
TextField ageInput = new TextField();
GridPane.setConstraints(ageInput, 3, 0, 2, 1);
TextField breedInput = new TextField();
GridPane.setConstraints(breedInput, 3, 2, 2, 1);
Now columns 3 and 4 contain those two text fields, column 3 contains the "Male" radio button, and column 4 contains the "Female" radio button.
I'm not sure if everything you posted is the whole form, but you might also want to increase the column span of the text area to make it work nicely:
GridPane.setConstraints(descriptionInput, 1, 4, 4, 1);
With those changes I get
(If it's important to you, you can avoid the "Female" check box from being pushed to the right by also setting the column span of the "Adoption" check box to 2.)
Another option is (starting with your original code) to wrap the two radio buttons in a HBox, and place the HBox in the grid pane instead of the radio buttons:
RadioButton pickMale = new RadioButton("Male");
pickMale.setToggleGroup(pickGender);
pickMale.setSelected(true);
RadioButton pickFemale = new RadioButton("Female");
pickFemale.setToggleGroup(pickGender);
HBox genderButtons = new HBox(4, pickMale, pickFemale);
GridPane.setConstraints(genderButtons, 3, 1);
// ...
formGrid.getChildren().addAll(colourLabel, colourInput, genderLabel, genderButtons);
However, I prefer the previous approach. (Your mileage may vary.)

How can I set the column properties(DisplayFormatString to be precise) of a aspx(devExpress) grid from code behind?

I have an aspx(devexpress) grid. Using which I generate columns dynamically from code behind.Below is the code from my grid_databinding event.
GridViewDataTextColumn bfield = new GridViewDataTextColumn();
if (TestString.YearSelectedNames.ToString().Length > 4)
{ string colName = string.Empty;
if (iCount % 2 == 0)
{
colName = TestString.YearSelectedNames.ToString().Substring(5, 4) + "-" + dtFreezing.Columns[iCount].ColumnName.ToString();
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), colName, iCount);
}
else
{
colName = TestString.YearSelectedNames.ToString().Substring(0, 4) + "-" + dtFreezing.Columns[iCount].ColumnName.ToString().Replace('1', ' ');
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), colName, iCount);
}
}
else
{
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), dtFreezing.Columns[iCount].ColumnName.Trim(), iCount);
}
bfield.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
bfield.HeaderStyle.Wrap = DevExpress.Utils.DefaultBoolean.True;
bfield.Name = dtFreezing.Columns[iCount].ColumnName.Trim();
bfield.Width = Unit.Pixel(120);
bfield.VisibleIndex = iCount;
bfield.DataItemTemplate = new DevxGridViewTemplate(ListItemType.Item, typeof(Label), dtFreezing.Columns[iCount].ColumnName.Trim(), iCount);
bfield.CellStyle.HorizontalAlign = HorizontalAlign.Right;
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
gridViewProductCrop.Columns.Add(bfield);
Here the line of code
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
is where I am trying to set the property of the grids' column to display only two decimals after the decimal point.
This line of code doesn't seem to work in the first place.
I have even tried using "{0:0.00}" and "{0:N2}" but in vain
Possible reason being that I am writing this line of code in the grid's databinding event. But how else can I set the column properties from code behind
Try to change this code
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
to
this.PropertiesTextEdit.DisplayFormatString = "N2";
i think this happen coz u loop the object(make a new object) and the properties would be overwrite.
CMIIW

Devexpress RespositoryLookUpEdit in grid , the value disaper

I have a devexpressgridcontrol. I want to use in one column of the grid : repositoryLookUpEdit.
I fill repositoryLookUpEdit with database question.
This question return three columns : IdPerson , Name and IdCity. Colums : IdPerson and Name have data but IdCity I have to set in appication.
So
- in gridcontrol the column Idcity has fildename : IdCity, and columnEdit : repositoryLookUpEdit.
- repositoryLookUpEdit has DisplayValue : CityName, and ValueMember: IdCity.
And my question is:
When I choose in grid in one row value of city and I go to another row, the value from the first row disaper.
What am I doing wrong? Could you give me some advise?
I use Devexpress 9.2.
this.gvPerson = new DevExpress.XtraGrid.Views.Grid.GridView();
this.replueCity = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
this.replueCity.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] { new DevExpress.XtraEditors.Controls.LookUpColumnInfo("IdCity", "IdCity", 20, DevExpress.Utils.FormatType.None, "", false, DevExpress.Utils.HorzAlignment.Default), new DevExpress.XtraEditors.Controls.LookUpColumnInfo("CityName", "CityName")});
this.replueCity.DisplayMember = "CityName";
this.replueCity.Name = "replueCity";
this.replueCity.NullText = "[Choose city]";
this.replueCity.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
this.replueOceny.ValueMember = "IdCity";
// CityColumn this.CityColumn.AppearanceCell.Options.UseTextOptions = true;
this.CityColumn.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
this.CityColumn.AppearanceCell.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;
this.CityColumn.Caption = "Ocena";
this.CityColumn.ColumnEdit = this.replueCity;
this.CityColumn.FieldName = "IdCity";
this.CityColumn.Name = "IdCityName";
this.CityColumn.Visible = true;
You have to set ValueMember for replueCity (which is the editor in the column). You set it only for replueOceny.
Check string IdCity in all three cases: it must be written exactly the same (mind the caps!).

C# datagrid each column width based on percent of total? asp.net

I have a DataGrid that's being populated with the code below, the code below makes the overall grid the size I want but it does set the column width. What I want to do is be able to say hey there is 'x' columns in a datatable and my tablewidth is 'xInt' divide xint by 'x' columns (which i've done, i'm just not sure have to set the column width...)
Thanks!
int tableWidth = 650;
int columnCount = dtTable.Columns.Count;
int columnWidth = Math.Abs(tableWidth / columnCount);
SupportContacts.ItemStyle.Wrap = true;
SupportContacts.Width = tableWidth;
SupportContacts.DataSource = dtTable;
SupportContacts.DataBind();
You could try the following (although I'm not sure if it will let you when you are auto-generating your columns).
foreach( DataGridColumn c in SupportContacts.Columns)
{
c.ItemStyle.Width = Unit.Point(columnWidth);
}

Resources