Hi,
suppose I have a table with one column in the database.
If I tried to display this table in a DataGridView it will be displayed in one vertical column.
I need to display this column in 3 or 4 columns in the gridview. but without repeating, just the data as it is in the DB table will be displayed in GV
Any help
16 10018
Are you saying you want to break that single column in the database up into several columns in a DataGridView?
How do you want to break it up? Every x rows, or by the height of the form? Please let me know if I'm even understanding your problem correctly.
Yeah, I want to break the single column in the database into several columns in the DataGridView, and I want to break them by the Height of the form
Thanks
Ok cool, that's what I thought but didn't want to assume.
Well, I'd imagine a good way to do this would be to load your data into another DataTable object in the way you want, then display that DataTable in your DGV object. You'll have to do some math to figure out the number of rows you'll want based on the DGV height, as well as update that if you want it to dynamically readjust itself if you resize the form. Also, remember that I believe you can resize the row height of a row in the DataGridView object.
Since the DGV is going to be displaying a different DataTable, you'll probably want to have events set up to reflect changes back into your original DataTable. You'll also need to make sure you're aware of how you map the new row/column representation back to the single column data in order to make sure you update the correct fields.
Does that seem reasonable? There might be a better way to do this... but I don't think there's any "automatic" way with DataGridView. I'll leave you with the general idea for you to try implementing, and if you have any questions, let me know.
You know, I was afraid to tell me that there is no other way but the DataTable :) Thank you for ur quick reply,
Nice day
I don't know how to do the select statement to separate the tables it, would u help -
public DataTable GetDataTable()
-
{
-
int scalar = GetProCount();
-
dbModule.InitConnection();
-
-
dbModule.cmd = new SqlCommand("SELECT ProName FROM ProductTable", dbModule.con);
-
dbModule.adptr = new SqlDataAdapter(dbModule.cmd);
-
dbModule.cmb = new SqlCommandBuilder(dbModule.adptr);
-
-
DataSet ds = new DataSet();
-
DataTable dt = new DataTable();
-
-
try
-
{
-
dt.Columns.Add("ProName", typeof(string));
-
dt.Columns.Add("الصنـــف2", typeof(string));
-
dt.Columns.Add("الصنـــف3", typeof(string));
-
dt.Columns.Add("الصنـــف4", typeof(string));
-
dt.Columns.Add("الصنـــف5", typeof(string));
-
-
dbModule.adptr.Fill(dt);
-
}
-
catch (Exception ex)
-
{
-
MessageBox.Show(ex.Message.ToString());
-
}
-
dbModule.DestroyConnection();
-
return dt;
-
}
-
-
I'd say just do a select statement that gets the whole thing and then divide it up. That way all your data is still stored in a single place that is easy to work with, you only manipulate it for viewing/editing purposes.
I did up a quick example for you... it's basically the solution (I wanted to see if I was actually right, not just feeding you bad theories :P) so if you want to figure it out for yourself, don't look right away. Keep in mind that I'm hard coding the number of columns I'm dividing the source column into... for your solution, you'd pass whatever columns you found to be appropriate based on the height of the form. http://members.shaw.ca/gtexmo/Code/C...ColumnDivider/
(Note, if you see any coding errors, please feel free to point them out. I did it rather quickly last night so I don't doubt that I may have made a mistake)
Yeah, Thank you, There is no errors of course :)
Really Thank you, you helped me a lot.
Hi
Sir
I want to break the single column in the database into several columns in the DataGridView, and I want to break them by the Height of the form
I am trying open the link you have given is not opening.
it says page not found. please help. http://members.shaw.ca/gtexmo/Code/C...ColumnDivider/
Thanks
Hasan @GaryTexmo
Interesting coincidence... I checked this forum after a long break, roughly 1 hour after you posted that haha.
I recently changed ISPs so all my links to my old web space are no longer valid. Fortunately I made a backup. Here is an archive with the files you're looking for.
Thanks a lot you have solved my problem
May be it was my lucky day
Just one more Thing how do i use SQLServer data in place of temporary data.
thanks @GaryTexmo
Just one more Thing how do i use SQLServer data in place of temporary data.
Thanks
Interesting coincidence... I checked this forum after a long break, roughly 1 hour after you posted that haha.
I recently changed ISPs so all my links to my old web space are no longer valid. Fortunately I made a backup. Here is an archive with the files you're looking for.
By temporary data, you mean the DataTable I created in the constructor? You should just be able to query your SQLServer and it should return a DataSet for you. I believe there should be a DataAdapter object (probably SQLDataAdapter) that you can set up with a command or connection. Executing it will return a DataSet with the results in it. If you're just doing a simple query, the DataSet will contain a single DataTable (assuming it was successful) and that's all the input you require.
Hopefully that answers your question :)
Thanks
Sorry for bad English.
I did so but I am confuse how do I replace dcValue(dataColumn) with my table Column.
Please have a look to my code. if I run it throws error Column '' does not belong to table.
Please Help
By temporary data, you mean the DataTable I created in the constructor? You should just be able to query your SQLServer and it should return a DataSet for you. I believe there should be a DataAdapter object (probably SQLDataAdapter) that you can set up with a command or connection. Executing it will return a DataSet with the results in it. If you're just doing a simple query, the DataSet will contain a single DataTable (assuming it was successful) and that's all the input you require.
Hopefully that answers your question :)
Sorry to bother u and for reposting my comment. I did not know that there is holiday in Canada.
I thought you did not receive so I reposted it.
Thanks
Hasan
Please don't repost your entire comment just to bump it. It was a holiday weekend in Canada so I wasn't checking the thread.
For your question, please read and understand what the code does. The variable, dcValue, is just the column I created for the purposes of your example. If your data table has a different column you want to split with, use that instead.
You don't need to construct dtMain... your adapter.Fill already gets you the dataset, so just pick the table you want and go from there. I think you can reference columns by names as well (look at DataTable.Columns["COLUMN_NAME"]).
Thanks Alot
Mr. GaryTexmo
Finaly its working its all because of you,
you are great.
Thanks again
Hasan
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian |
last post by:
I've got a couple questions on the new Datagridview control in VS2005.
1) In the old datagrid control at design time I was able to add multiple
tablestyles with columns from different...
|
by: Crazy Cat |
last post by:
In the following code I retrieve data from a stored procedure that
returns multiple resultsets (the results of the stored procedure have
been stored in a datareader called reader). On each...
|
by: DBC User |
last post by:
Hi All,
I am using a database which doesn't suppport and since I am using ORM I
can not use join query to create table object mapping. So my question
is
I have a master table which has bunch...
|
by: Mitchell S. Honnert |
last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?
Here's...
|
by: Mike |
last post by:
Hey everyone...
I've got three problems with a custom DataGridView column I've built
following the "How To: Host Controls in Windows Forms DataGridView
Cells" article. The base editing control...
|
by: Johnny E. Jensen |
last post by:
Hello
Dot sure if this it the right group but here goes.
I'am using the DataGridView multiple times in my application, and then i'll
read a book on inherience, and that opend a new world for...
|
by: LostInMD |
last post by:
Hi All :)
I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
|
by: =?Utf-8?B?TG9zdEluTUQ=?= |
last post by:
Hi All :)
I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView.
True DBGrid has a MultipleLines property that controls whether individual
records span multiple lines. Is...
|
by: Zack00000 |
last post by:
Hi,
Is there a way to optimize the DataGridView in terms of drawing speed? The application that I'm building will need to use multiple datagridview controls which will get updated around every...
|
by: msgjunkie |
last post by:
I have 3 related tables in a DataSet - Customers, Products and Orders.
I am trying to create an "editable" DataGridView which, ideally, will contain columns from all the tables. I have tried...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |