GridView Column TextWrap like Excel in c# windows - c#

I have a grid view containing column names a bit lengthy which are coming from database. So i want to make the wrapping like what we do in Excel in multiline rather than making the column fit to the length.
I used
dataGridView1.Columns["abcdefghijklmnop"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dataGridView1.Columns["abcdefghijklmnop"].DefaultCellStyle.WrapMode=DataGridViewTriState.True;
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
When i do this i am able to fit the column length to the text length.but i want it to be in multiline.
Example : Should be like this
-------------------------------------------------
| abcde | klmno | uvwxy |
| fghij | pqrst | z |
-------------------------------------------------
Team1 | | | |
Team2 | | | |
TeamN | | | |
-------------------------------------------------
Now it is coming like this
-------------------------------------------------
| abcdefghij | klmnopqrst | uvwxyz |
| | | |
-------------------------------------------------
Team1 | | | |
Team2 | | | |
TeamN | | | |
-------------------------------------------------
these are the properties i am having
Pls help!!

You can do it many ways for example:
![dataGridView1.Columns\[0\].HeaderText = "VeryLong " + "LongLong" + Environment.NewLine + "LongLongLong";][1]
OR
dataGridView.ColumnHeadersHeightSizeMode =
DataGridViewColumnHeadersHeightSizeMode.AutoSize;
foreach (DataGridViewColumn column in dataGridView.Columns)
{
column.HeaderCell.Style.WrapMode= DataGridViewTriState.True;
}
Finally through edit datagridview columns manually:

Related

WPF Datagrid or maybe something else that can have indents in the first column?

I have a table with a bunch of data this is a small sample:
Header - Object name
Waarde
ExportRoot.a80_02_00_01_Status.Settings.Off
0
ExportRoot.a80_02_00_01_Status.Standby
0
ExportRoot.a80_02_00_01_Status.Cooling
1
ExportRoot.a80_02_00_01_Status.Drying
0
ExportRoot.a80_02_00_01_Status.Heating
0
ExportRoot.a80_02_00_01_Status.PrepDrain
0
I wish to style this table in a way to where its more readable by removing the object parts and indenting the table like how it looks below.
| Header - Object name | Waarde |
|--------------------------|---------|
| ExportRoot | |
| | a80_02_00_01_Status | |
| | | Settings | |
| | | | Off | 0 |
| | | | Standby | 0 |
| | | | Cooling | 1 |
| | | | Drying | 0 |
| | | | Heating | 0 |
| | | | PrepDrain | 0 |
Is there a way of doing this and if so what should I be looking for all I've found so far are tables with sub tables and that not exactly what I'm looking for. If anyone has an idea let me know I'm super lost.
So basically you need a TreeListView:
There is one project on CodeProject that you can check:
WPF TreeListView Control
There is also commercial products, like DevExpress:
DevExpress TreeList View

Notify in .NET application if SQL data has changed

I have got two tables. Table A contains the main data in every change state, Table B has the detail data.
Table A
| ID | Name |
| 1 | House |
| 2 | Tree |
| 3 | Car |
Table B
| ID | FK | DateTime | Color | Type |
| 1 | 1 | 2017-26-01T13:00:00 | Red | Bungalow |
| 2 | 2 | 2017-26-01T13:05:00 | Brown | Oak |
| 3 | 1 | 2017-26-01T13:10:00 | Green | Bungalow |
| 4 | 3 | 2017-26-01T13:15:00 | Yellow | Smart |
| 5 | 1 | 2017-26-01T13:20:00 | White | Bungalow |
| 6 | 3 | 2017-26-01T13:25:00 | Black | Smart |
Result to watch
| ID | Name | DateTime | Color | Type |
| 1 | House | 2017-26-01T13:20:00 | White | Bungalow |
| 2 | Tree | 2017-26-01T13:05:00 | Brown | Oak |
| 3 | Car | 2017-26-01T13:25:00 | Black | Smart |
The current state of an entity in Table A is described by the record with the youngest timestamp in Table B.
Now, I want to be nofitied, if an entity gets a new state (new record in Table B) or a new entity is created (new records in Table A and B), i.e. it could look like.
New result to watch
| ID | Name | DateTime | Color | Type |
| 1 | House | 2017-26-01T13:20:00 | White | Bungalow |
| 2 | Tree | 2017-26-01T13:05:00 | Brown | Oak |
| 3 | Car | 2017-26-01T19:25:00 | Silver | Smart |
| 4 | Dog | 2017-26-01T20:25:00 | White / Black | Poodle |
With SqlDependency it is not possible to be notified for a statement which contains GROUP BY with MAX aggregate, window functions or TOP clause. So I have no idea how I can get the last detail data for an entity.
Is there any possibility to create a statement for this requirement or are there any other ways to be notified after changes for this result?
You can create and use SQL Triggers usin CLR
Here - SQL Trigger CLR

i want my datagridview 1st n 2nd column to be fixed n remaining columns should be enter by user

|BrandName| ML | STOCK |
| | | |
|PEPSI | 100 | |
| | | |
|LIMCA | 200 | |
| | | |
I Want my DataGridView to look like above table.
and how to save the data after entering stock.
You have a Frozen property for each column of the DataGridView. You juste have to set it to True.
dataGridView.Columns[0].Frozen = true;
dataGridView.Columns[1].Frozen = true;
Would've been pretty easy to Google up, don't you think?

MySQL Subquery Display in UPPERCASE

[DONE] for those who need this.. I will edit this and put the answer below..
How to make LName and FName all CAPS using subquery?
I already make all LName and FName CAPS but not in subquery using this code
Select UPPER(LName) AS "Lastname", UPPER(FName) AS "Firstname" FROM Trainers;
OUTPUT:
+-----------+-----------+
| Lastname | Firstname |
+-----------+-----------+
| MONTANO | GERALD |
| ALEJANDRO | LEONARD |
| MONTEZ | GARY |
| GUILLERMO | JACKIE |
| SANCHEZ | VERNA |
| GABORNI | MICHELLE |
+-----------+-----------+
Table Trainers
+-----------+-----------+----------+-------+
| TrainerNo | LName | FName | Rate |
+-----------+-----------+----------+-------+
| 00804871 | Montano | Gerald | 200 |
| 00807461 | Alejandro | Leonard | 175 |
| 00807462 | Montez | Gary | 150 |
| 00823253 | Guillermo | Jackie | 200 |
| 00827320 | Sanchez | Verna | 125 |
| 00845907 | Gaborni | Michelle | 150 |
+-----------+-----------+----------+-------+
ANSWER:
Select UPPER(Lname) AS "Lastname", UPPER(FName) AS "Firstname" from Trainers Where Rate <= (Select Max(Rate) from Trainers);
IF you want to return the first name concatenated with the second name in upper case in a sub-query. Then you can do this.
Select * from Table Name, (Select UPPER(LName) + UPPER(FName) FROM Trainers) as Name

merge single table column with different types

Table Columns
or_cv_no
here is where 'cv_no' and 'or_no' stored
type
different types are 'CV' and 'OR'
amount
here is where 'cv_amt' and 'or_amt' stored
date
data that is being fetched has same date
my query is this
SELECT IIF(type = 'CV', or_cv_no) AS cv_no, IIF(type = 'CV', amount) AS cv_amt, IIF(type = 'OR', or_cv_no) AS or_no, IIF(type = 'OR', amount) AS or_amt FROM transacAmt
and the output is
how can i output it to look like this sample:
| cv_no | cv_amt | or_no | or_amt |
|---------------------------------|
| 1234 | 1,500 | 4321 | 1,200 |
|-------+--------+-------+--------|
| 7777 | 1,700 | 2222 | 1,760 |
|-------+--------+-------+--------|
| 1111 | 1,900 | 3333 | 1,530 |
|-------+--------+-------+--------|
| | | 5355 | 1,420 |
|-------+--------+-------+--------|
| | | 1355 | 4,566 |
EDIT: The output must be like this: marked 'x' must be removed.. or be filled by data

Categories