0

I have a SQL Insert statement that is populating a GridControl (works). I need to make the visibility false for the Primary and Foreign Keys columns. I also want the Double_Click event to populated pre-existing textboxes, and checkboxes, based off of the Primary Key that was selected.

Example:

I have these as columns: PK / FK / source (string) / path (string) / destination (string) / register (checkbox) / register2 (checkbox) / arguments (string)

I need to hide columns 1 & 2. I need to populate the textboxes and checkboxes, when double clicked, based off of the PK and FK.

I can't seem to find the class that grabs the information. I can figure everything else out (I think).

I have looked on the DevExpress site and it's not very helpful. I have tried these things:

https://www.devexpress.com/Support/Center/Question/Details/A2934 https://www.devexpress.com/Support/Center/Question/Details/T156269

How to set the default Sort on a DevExpress GridView

And also trying to create a list based off of the row. That didn't work either. Ideas?

Community
  • 1
  • 1
Kevin Fischer
  • 371
  • 7
  • 16

1 Answers1

1

To hide columns, you need to get a handle for the MainView (Assuming you only have a single level of data, i.e. not a nested master/detail or something).

 GridControl ctl = new GridControl(); // use your existing GridControl instead of creating a new one here
     var view = (GridView) ctl.DefaultView;

Then you can hide either by index, or by name.

view.Columns[0].Visible = false;

OR

view.Columns["PK"].Visible = false;

Then, to get values, is kind of obfuscated (as it seems a lot of the devexpress stuff is). TBy far the easiest way is to databind them, but if that's not possible there are other options available. That part is already answered well here.

Community
  • 1
  • 1
DrewJordan
  • 5,266
  • 1
  • 25
  • 39
  • I think the GridControl class is a Version 14 addition. I'm working with 10.1.6. I don't have access to GridControl. – Kevin Fischer Apr 17 '15 at 20:16
  • Do you mean `GridView`? Because your question's first sentence is "I have a SQL Insert statement that is populating a GridControl (works). " and you mention GridControl in the title. And it's tagged with GridControl. I'm confused... – DrewJordan Apr 17 '15 at 20:18
  • No, it's a DevExpress.XtraGrid.GridControl – Kevin Fischer Apr 17 '15 at 20:22
  • You're saying that's what the one you're working with is, right? That's the same thing I'm working with... If you add a `using Devexpress.XtraGrid;` statement to your class then you don't have to type the entire namespace each time. – DrewJordan Apr 17 '15 at 20:35
  • My using was DevExpress.XtraGrid.Views. Let's see what I get. One sec. Also, thank you! – Kevin Fischer Apr 17 '15 at 20:38
  • GridControl control = new GridControl(); var view = (GridView)control.DefaultView; view.Columns[0].Visible = false; view.Columns[1].Visible = false; is producing a null value for the control – Kevin Fischer Apr 17 '15 at 20:47
  • 1
    I mean, the code I posted was meant to be an example... The null reference is probably because we don't actually have any columns added. If you've already got a working `GridControl` you should just try `var view = (GridView)control.DefaultView; view.Columns[0].Visible = false;` and see if it will hide your first column. – DrewJordan Apr 17 '15 at 21:05
  • Okay, perfect! Now the selection part – Kevin Fischer Apr 17 '15 at 21:19
  • Well, like I said, there's already a great answer for that and you should reference that, rather than have me repeat it here... Basically you can use various properties of the same `GridView` you just got to get the values. Since you've already got a databound source it should be pretty easy. – DrewJordan Apr 17 '15 at 21:26